YARP
Yet Another Robot Platform
OpenCVGrabber.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-FileCopyrightText: 2006 Eric Mislivec
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  */
7 
8 #ifndef YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
9 #define YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
10 
11 /*
12  * A YARP frame grabber device driver using OpenCV to implement
13  * image capture from cameras and AVI files.
14  */
15 
16 
17 #include <yarp/os/Property.h>
19 #include <yarp/dev/DeviceDriver.h>
20 #include <yarp/os/Stamp.h>
22 
23 #include <opencv2/highgui/highgui.hpp>
24 
35 {
36 public:
37 
44  m_w(0),
45  m_h(0),
46  m_loop(false),
47  m_saidSize(false),
48  m_saidResize(false),
49  fromFile(false),
50  m_cap(),
51  m_transpose(false),
52  m_flip_x(false),
53  m_flip_y(false)
54  {}
55 
57  virtual ~OpenCVGrabber() { ; }
58 
59 
60 
61  bool open(yarp::os::Searchable & config) override;
62 
63  bool close() override;
64 
66 
67 
70  inline int height() const override { return m_h; }
71 
74  inline int width() const override { return m_w; }
75 
80  inline yarp::os::Stamp getLastInputStamp() override { return m_laststamp; }
81 
82 protected:
83 
85  int m_w;
87  int m_h;
88 
90  bool m_loop;
91 
92  bool m_saidSize;
94 
96  bool fromFile;
97 
99  cv::VideoCapture m_cap;
100 
101  /* optional image modifiers */
103  bool m_flip_x;
104  bool m_flip_y;
105 
108 
110 };
111 
112 #endif // YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
opencv_grabber: An image frame grabber device using OpenCV to capture images from cameras and AVI fil...
Definition: OpenCVGrabber.h:35
yarp::os::Stamp getLastInputStamp() override
Implements the IPreciselyTimed interface.
Definition: OpenCVGrabber.h:80
int height() const override
Get the height of images a grabber produces.
Definition: OpenCVGrabber.h:70
OpenCVGrabber()
Create an OpenCV image grabber.
Definition: OpenCVGrabber.h:43
virtual ~OpenCVGrabber()
Destroy an OpenCV image grabber.
Definition: OpenCVGrabber.h:57
bool fromFile
Whether reading from file or camera.
Definition: OpenCVGrabber.h:96
int width() const override
Get the width of images a grabber produces.
Definition: OpenCVGrabber.h:74
yarp::os::Property m_config
Saved copy of the device configuration.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Read an image from the grabber.
bool close() override
Close a grabber.
cv::VideoCapture m_cap
OpenCV image capture object.
Definition: OpenCVGrabber.h:99
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::os::Stamp m_laststamp
int m_w
Width of the images a grabber produces.
Definition: OpenCVGrabber.h:85
int m_h
Height of the images a grabber produces.
Definition: OpenCVGrabber.h:87
bool m_loop
Whether to loop or not.
Definition: OpenCVGrabber.h:90
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
A class for storing options and configuration information.
Definition: Property.h:34
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22