YARP
Yet Another Robot Platform
IFrameGrabberImage-inl.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_DEV_IFRAMEGRABBERIMAGE_INL_H
8 #define YARP_DEV_IFRAMEGRABBERIMAGE_INL_H
9 
10 #include <yarp/sig/ImageUtils.h>
11 #include <yarp/os/LogComponent.h>
12 
14 
15 namespace yarp {
16 namespace dev {
17 
18 template <typename ImageType>
20  yarp::sig::VectorOf<std::pair<int, int>> vertices,
21  ImageType& image)
22 {
23  if (cropType == YARP_CROP_RECT) {
24  if (vertices.size() != 2) {
25  yCError(IFRAMEGRABBEROF, "GetImageCrop failed: RECT mode requires 2 vertices");
26  return false;
27  }
28  ImageType full;
29  getImage(full);
30 
31  if (!yarp::sig::utils::cropRect(full, vertices[0], vertices[1], image)) {
32  yCError(IFRAMEGRABBEROF, "GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
33  vertices[0].first,
34  vertices[0].second,
35  vertices[1].first,
36  vertices[1].second);
37  return false;
38  }
39  } else if(cropType == YARP_CROP_LIST) {
40  yCError(IFRAMEGRABBEROF, "List type not yet implemented");
41  return false;
42  }
43 
44  return true;
45 }
46 
47 } // namespace dev
48 } // namespace yarp
49 
50 #endif // YARP_DEV_IFRAMEGRABBERIMAGE_INL_H
const yarp::os::LogComponent & IFRAMEGRABBEROF()
cropType_id_t
@ YARP_CROP_LIST
@ YARP_CROP_RECT
virtual bool getImageCrop(cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int >> vertices, ImageType &image)
Get a crop of the image from the frame grabber.
Provides:
Definition: Vector.h:119
#define yCError(component,...)
Definition: LogComponent.h:154
#define YARP_DECLARE_LOG_COMPONENT(name)
Definition: LogComponent.h:74
bool cropRect(const yarp::sig::Image &inImg, const std::pair< unsigned int, unsigned int > &vertex1, const std::pair< unsigned int, unsigned int > &vertex2, yarp::sig::Image &outImg)
Crop a rectangle area out of an image given two opposite vertices.
Definition: ImageUtils.cpp:113
The main, catch-all namespace for YARP.
Definition: dirs.h:16