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 std::vector<yarp::dev::vertex_t> vertices,
21{
22 if (cropType == YARP_CROP_RECT) {
23 if (vertices.size() != 2) {
24 yCError(IFRAMEGRABBEROF, "GetImageCrop failed: RECT mode requires 2 vertices");
26 }
27 ImageType full;
28 yarp::dev::ReturnValue b = getImage(full);
29 if (!b || full.width() == 0 || full.height() == 0)
30 {
31 yCError(IFRAMEGRABBEROF, "GetImageCrop failed: No image received");
33 }
34
35 std::pair<unsigned int, unsigned int> v0;
36 v0.first = vertices[0].x;
37 v0.second = vertices[0].y;
38 std::pair<unsigned int, unsigned int> v1;
39 v1.first = vertices[1].x;
40 v1.second = vertices[1].y;
41 if (!yarp::sig::utils::cropRect(full, v0, v1, image)) {
42 yCError(IFRAMEGRABBEROF, "GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
43 vertices[0].x,
44 vertices[0].y,
45 vertices[1].x,
46 vertices[1].y);
48 }
49 } else if(cropType == YARP_CROP_LIST) {
50 yCError(IFRAMEGRABBEROF, "List type not yet implemented");
52 }
53
54 return ReturnValue_ok;
55}
56
57} // namespace yarp::dev
58
59#endif // YARP_DEV_IFRAMEGRABBERIMAGE_INL_H
const yarp::os::LogComponent & IFRAMEGRABBEROF()
#define ReturnValue_ok
Definition ReturnValue.h:80
virtual yarp::dev::ReturnValue getImageCrop(yarp::dev::cropType_id_t cropType, std::vector< vertex_t > vertices, ImageType &image)
Get a crop of the image from the frame grabber.
@ return_value_error_generic
Method was successfully executed.
@ return_value_error_method_failed
Method is deprecated.
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
#define yCError(component,...)
#define YARP_DECLARE_LOG_COMPONENT(name)
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.