YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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>
12
14
15namespace yarp::dev {
16
17template <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 bool b = getImage(full);
29 if (!b || full.width() == 0 || full.height() == 0)
30 {
31 yCError(IFRAMEGRABBEROF, "GetImageCrop failed: No image received");
32 return false;
33 }
34
35 if (!yarp::sig::utils::cropRect(full, vertices[0], vertices[1], image)) {
36 yCError(IFRAMEGRABBEROF, "GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
37 vertices[0].first,
38 vertices[0].second,
39 vertices[1].first,
40 vertices[1].second);
41 return false;
42 }
43 } else if(cropType == YARP_CROP_LIST) {
44 yCError(IFRAMEGRABBEROF, "List type not yet implemented");
45 return false;
46 }
47
48 return true;
49}
50
51} // namespace yarp::dev
52
53#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.
size_t width() const
Gets width of image in pixels.
Definition Image.h:163
size_t height() const
Gets height of image in pixels.
Definition Image.h:169
size_t size() const
Definition Vector.h:322
#define yCError(component,...)
#define YARP_DECLARE_LOG_COMPONENT(name)
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
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.