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::dev {
16 
17 template <typename ImageType>
19  yarp::sig::VectorOf<std::pair<int, int>> vertices,
20  ImageType& image)
21 {
22  if (cropType == YARP_CROP_RECT) {
23  if (vertices.size() != 2) {
24  yCError(IFRAMEGRABBEROF, "GetImageCrop failed: RECT mode requires 2 vertices");
25  return false;
26  }
27  ImageType full;
28  getImage(full);
29 
30  if (!yarp::sig::utils::cropRect(full, vertices[0], vertices[1], image)) {
31  yCError(IFRAMEGRABBEROF, "GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
32  vertices[0].first,
33  vertices[0].second,
34  vertices[1].first,
35  vertices[1].second);
36  return false;
37  }
38  } else if(cropType == YARP_CROP_LIST) {
39  yCError(IFRAMEGRABBEROF, "List type not yet implemented");
40  return false;
41  }
42 
43  return true;
44 }
45 
46 } // namespace yarp::dev
47 
48 #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:117
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_DECLARE_LOG_COMPONENT(name)
Definition: LogComponent.h:73
For streams capable of holding different kinds of content, check what they actually have.
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