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 
49 {
50 public:
51 
60  OpenCVGrabber() : IFrameGrabberImage(), DeviceDriver(),
61  m_w(0),
62  m_h(0),
63  m_loop(false),
64  m_saidSize(false),
65  m_saidResize(false),
66  fromFile(false),
67  m_cap(),
68  m_transpose(false),
69  m_flip_x(false),
70  m_flip_y(false)
71  {}
72 
74  virtual ~OpenCVGrabber() { ; }
75 
76 
77 
78  bool open(yarp::os::Searchable & config) override;
79 
80  bool close() override;
81 
83  virtual bool sendImage(const cv::Mat & frame, yarp::sig::ImageOf<yarp::sig::PixelRgb> & image);
84 
85 
88  inline int height() const override { return m_h; }
89 
92  inline int width() const override { return m_w; }
93 
98  inline yarp::os::Stamp getLastInputStamp() override { return m_laststamp; }
99 
100 protected:
101 
103  size_t m_w;
105  size_t m_h;
106 
108  bool m_loop;
109 
112 
114  bool fromFile;
115 
117  cv::VideoCapture m_cap;
118 
119  /* optional image modifiers */
121  bool m_flip_x;
122  bool m_flip_y;
123 
126 
128 };
129 
130 
140 #endif // YARP_OPENCV_GRABBER_DEVICE_OPENCVGRABBER_H
define common interfaces to discover remote camera capabilities
An image frame grabber device using OpenCV to capture images from cameras and AVI files.
Definition: OpenCVGrabber.h:49
yarp::os::Stamp getLastInputStamp() override
Implements the IPreciselyTimed interface.
Definition: OpenCVGrabber.h:98
int height() const override
Get the height of images a grabber produces.
Definition: OpenCVGrabber.h:88
OpenCVGrabber()
Create an OpenCV image grabber.
Definition: OpenCVGrabber.h:60
virtual ~OpenCVGrabber()
Destroy an OpenCV image grabber.
Definition: OpenCVGrabber.h:74
bool fromFile
Whether reading from file or camera.
virtual bool sendImage(const cv::Mat &frame, yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
Read an image from the grabber.
int width() const override
Get the width of images a grabber produces.
Definition: OpenCVGrabber.h:92
yarp::os::Property m_config
Saved copy of the device configuration.
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.
bool close() override
Close a grabber.
cv::VideoCapture m_cap
OpenCV image capture object.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
size_t m_h
Height of the images a grabber produces.
yarp::os::Stamp m_laststamp
size_t m_w
Width of the images a grabber produces.
bool m_loop
Whether to loop or not.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Read a YARP-format image from a device.
A class for storing options and configuration information.
Definition: Property.h:37
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25