YARP
Yet Another Robot Platform
OpenCVGrabber.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * Copyright (C) 2006 Eric Mislivec
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
22 #define YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
23 
24 /*
25  * A YARP frame grabber device driver using OpenCV to implement
26  * image capture from cameras and AVI files.
27  */
28 
29 
30 #include <yarp/os/Property.h>
32 #include <yarp/dev/DeviceDriver.h>
33 #include <yarp/os/Stamp.h>
35 
36 #include <opencv2/highgui/highgui.hpp>
37 
48 {
49 public:
50 
56  OpenCVGrabber() : IFrameGrabberImage(), DeviceDriver(),
57  m_w(0),
58  m_h(0),
59  m_loop(false),
60  m_saidSize(false),
61  m_saidResize(false),
62  fromFile(false),
63  m_cap(),
64  m_transpose(false),
65  m_flip_x(false),
66  m_flip_y(false)
67  {}
68 
70  virtual ~OpenCVGrabber() { ; }
71 
72 
73 
74  bool open(yarp::os::Searchable & config) override;
75 
76  bool close() override;
77 
79  virtual bool sendImage(const cv::Mat & frame, yarp::sig::ImageOf<yarp::sig::PixelRgb> & image);
80 
81 
84  inline int height() const override { return m_h; }
85 
88  inline int width() const override { return m_w; }
89 
94  inline yarp::os::Stamp getLastInputStamp() override { return m_laststamp; }
95 
96 protected:
97 
99  size_t m_w;
101  size_t m_h;
102 
104  bool m_loop;
105 
108 
110  bool fromFile;
111 
113  cv::VideoCapture m_cap;
114 
115  /* optional image modifiers */
117  bool m_flip_x;
118  bool m_flip_y;
119 
122 
124 };
125 
126 #endif // YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
OpenCVGrabber::m_saidResize
bool m_saidResize
Definition: OpenCVGrabber.h:107
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
OpenCVGrabber::m_cap
cv::VideoCapture m_cap
OpenCV image capture object.
Definition: OpenCVGrabber.h:113
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
OpenCVGrabber::~OpenCVGrabber
virtual ~OpenCVGrabber()
Destroy an OpenCV image grabber.
Definition: OpenCVGrabber.h:70
OpenCVGrabber::m_h
size_t m_h
Height of the images a grabber produces.
Definition: OpenCVGrabber.h:101
yarp::sig::ImageOf< yarp::sig::PixelRgb >
OpenCVGrabber::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: OpenCVGrabber.cpp:71
OpenCVGrabber::m_saidSize
bool m_saidSize
Definition: OpenCVGrabber.h:106
OpenCVGrabber::close
bool close() override
Close a grabber.
Definition: OpenCVGrabber.cpp:164
OpenCVGrabber::m_flip_x
bool m_flip_x
Definition: OpenCVGrabber.h:117
Property.h
OpenCVGrabber::getImage
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an rgb image from the frame grabber, if required demosaicking/color reconstruction is applied.
Definition: OpenCVGrabber.cpp:227
OpenCVGrabber::width
int width() const override
Get the width of images a grabber produces.
Definition: OpenCVGrabber.h:88
yarp::dev::IFrameGrabberImage
Read a YARP-format image from a device.
Definition: FrameGrabberInterfaces.h:241
Stamp.h
OpenCVGrabber::sendImage
virtual bool sendImage(const cv::Mat &frame, yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
Read an image from the grabber.
Definition: OpenCVGrabber.cpp:182
OpenCVGrabber::OpenCVGrabber
OpenCVGrabber()
Create an OpenCV image grabber.
Definition: OpenCVGrabber.h:56
OpenCVGrabber::m_w
size_t m_w
Width of the images a grabber produces.
Definition: OpenCVGrabber.h:99
OpenCVGrabber::m_transpose
bool m_transpose
Definition: OpenCVGrabber.h:116
FrameGrabberInterfaces.h
define common interfaces to discover remote camera capabilities
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
OpenCVGrabber::m_flip_y
bool m_flip_y
Definition: OpenCVGrabber.h:118
OpenCVGrabber
opencv_grabber: An image frame grabber device using OpenCV to capture images from cameras and AVI fil...
Definition: OpenCVGrabber.h:48
OpenCVGrabber::m_config
yarp::os::Property m_config
Saved copy of the device configuration.
Definition: OpenCVGrabber.h:121
OpenCVGrabber::getLastInputStamp
yarp::os::Stamp getLastInputStamp() override
Implements the IPreciselyTimed interface.
Definition: OpenCVGrabber.h:94
OpenCVGrabber::fromFile
bool fromFile
Whether reading from file or camera.
Definition: OpenCVGrabber.h:110
OpenCVGrabber::m_loop
bool m_loop
Whether to loop or not.
Definition: OpenCVGrabber.h:104
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
OpenCVGrabber::height
int height() const override
Get the height of images a grabber produces.
Definition: OpenCVGrabber.h:84
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
DeviceDriver.h
OpenCVGrabber::m_laststamp
yarp::os::Stamp m_laststamp
Definition: OpenCVGrabber.h:123