YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeFrameGrabber.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_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
8#define YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
9
10
11#include <yarp/sig/ImageFile.h>
17#include <yarp/os/Searchable.h>
18#include <yarp/os/Thread.h>
19#include <yarp/os/Time.h>
20#include <yarp/os/Vocab.h>
21#include <yarp/os/Log.h>
22#include <yarp/os/Value.h>
24
25#include <cstdio>
26#include <random>
27#include <condition_variable>
29
41#ifndef YARP_NO_DEPRECATED // Since YARP 3.5`
42 virtual public yarp::dev::DeviceDriver,
43#else
45#endif
52 public yarp::os::Thread,
55{
56public:
57 FakeFrameGrabber() = default;
62 ~FakeFrameGrabber() override = default;
63
64 bool close() override;
65
70 bool open(yarp::os::Searchable& config) override;
71
72 // yarp::os::PortReader
73 bool read(yarp::os::ConnectionReader& connection) override;
74
75 // yarp::os::Thread
76 void run() override;
77 void onStop() override;
78
79 void timing();
80
81 //IRgbVisualParams
82 int getRgbHeight() override;
83 int getRgbWidth() override;
84 yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector<yarp::dev::CameraConfig>& configurations) override;
87 yarp::dev::ReturnValue getRgbFOV(double& horizontalFov, double& verticalFov) override;
88 yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override;
90 yarp::dev::ReturnValue getRgbMirroring(bool& mirror) override;
91 yarp::dev::ReturnValue setRgbMirroring(bool mirror) override;
92
93 //IFrameGrabberImage
94 int height() const override;
95 int width() const override;
99 std::vector<yarp::dev::vertex_t> vertices,
102 std::vector<yarp::dev::vertex_t> vertices,
104
105 //IPreciselyTimed
107
108 //IFrameGrabberControls Interface
113 yarp::dev::ReturnValue setFeature(yarp::dev::cameraFeature_id_t feature, double value1, double value2) override;
114 yarp::dev::ReturnValue getFeature(yarp::dev::cameraFeature_id_t feature, double& value1, double& value2) override;
124
125 //IFrameGrabberControlsDC1394 Interface
126 yarp::dev::ReturnValue getVideoModeMaskDC1394(unsigned int& val) override;
127 yarp::dev::ReturnValue getVideoModeDC1394(unsigned int& val) override;
128 yarp::dev::ReturnValue setVideoModeDC1394(int video_mode) override;
129 yarp::dev::ReturnValue getFPSMaskDC1394(unsigned int& val) override;
130 yarp::dev::ReturnValue getFPSDC1394(unsigned int& val) override;
132 yarp::dev::ReturnValue getISOSpeedDC1394(unsigned int& val) override;
133 yarp::dev::ReturnValue setISOSpeedDC1394(int speed) override;
134 yarp::dev::ReturnValue getColorCodingMaskDC1394(unsigned int video_mode,unsigned int& val) override;
135 yarp::dev::ReturnValue getColorCodingDC1394(unsigned int& val) override;
136 yarp::dev::ReturnValue setColorCodingDC1394(int coding) override;
137 yarp::dev::ReturnValue getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep) override;
138 yarp::dev::ReturnValue getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0) override;
139 yarp::dev::ReturnValue setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0) override;
143 yarp::dev::ReturnValue getTransmissionDC1394(bool& bTxON) override;
144 yarp::dev::ReturnValue setBroadcastDC1394(bool onoff) override;
147 yarp::dev::ReturnValue setPowerDC1394(bool onoff) override;
148 yarp::dev::ReturnValue setCaptureDC1394(bool bON) override;;
149 yarp::dev::ReturnValue getBytesPerPacketDC1394(unsigned int& bpp) override;
151
152private:
153 static constexpr size_t default_w = 128;
154 static constexpr size_t default_h = 128;
155 static constexpr size_t default_freq = 30;
156 static constexpr double default_snr = 0.5;
157
158 yarp::os::Port m_rpcPort;
159
160 size_t m_ct{0};
161 size_t m_bx{0};
162 size_t m_by{0};
163 unsigned long m_rnd{0};
164 double prev{0};
165 bool m_have_bg{false};
166
167 yarp::os::Property m_intrinsic;
168 std::vector<yarp::dev::CameraConfig> configurations;
169
170 std::random_device rnddev;
171 std::default_random_engine randengine{rnddev()};
172 std::uniform_int_distribution<int> udist{-1, 1};
173 std::uniform_real_distribution<double> ucdist{0.0, 1.0};
174
175 std::mutex curr_buff_mutex;
176 size_t curr_buff{1};
178 bool img_ready[2] {false, false};
179 bool img_consumed[2] {true, true};
180 std::mutex mutex[2]; // FIXME C++17 perhaps use shared_mutex (check if this causes starvation)
181 std::condition_variable img_ready_cv[2];
182 std::condition_variable img_consumed_cv[2];
183 double buff_ts[2];
184 mutable std::mutex rpc_methods_mutex;
185
188 yarp::os::Stamp stamp;
189
191 double& timestamp);
192
193 bool makeSimpleBayer(yarp::sig::ImageOf<yarp::sig::PixelRgb>& src,
195
196 void printTime(unsigned char* pixbuf, size_t pixbuf_w, size_t pixbuf_h, size_t x, size_t y, char* s, size_t size);
197};
198
199#endif // YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
CameraDescriptor camera
FeatureMode mode
This class is the parameters parser for class FakeFrameGrabber.
fakeFrameGrabber: A fake camera for testing.
int width() const override
Return the width of each frame.
yarp::dev::ReturnValue getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
yarp::dev::ReturnValue getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
yarp::dev::ReturnValue setResetDC1394() override
int getRgbWidth() override
Return the width of each frame.
yarp::dev::ReturnValue setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
int getRgbHeight() override
Return the height of each frame.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
yarp::dev::ReturnValue setMode(yarp::dev::cameraFeature_id_t feature, yarp::dev::FeatureMode mode) override
Set the requested mode for the feature.
yarp::dev::ReturnValue setPowerDC1394(bool onoff) override
yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
yarp::dev::ReturnValue getTransmissionDC1394(bool &bTxON) override
yarp::dev::ReturnValue getColorCodingDC1394(unsigned int &val) override
yarp::dev::ReturnValue setBytesPerPacketDC1394(unsigned int bpp) override
yarp::dev::ReturnValue getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
yarp::dev::ReturnValue setTransmissionDC1394(bool bTxON) override
yarp::dev::ReturnValue getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue getISOSpeedDC1394(unsigned int &val) override
yarp::dev::ReturnValue setFPSDC1394(int fps) override
yarp::dev::ReturnValue getVideoModeDC1394(unsigned int &val) override
int height() const override
Return the height of each frame.
yarp::dev::ReturnValue setActive(yarp::dev::cameraFeature_id_t feature, bool onoff) override
Set the requested feature on or off.
yarp::dev::ReturnValue setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0) override
~FakeFrameGrabber() override=default
FakeFrameGrabber & operator=(FakeFrameGrabber &&)=delete
yarp::dev::ReturnValue getOperationModeDC1394(bool &b1394) override
FakeFrameGrabber & operator=(const FakeFrameGrabber &)=delete
yarp::dev::ReturnValue setDefaultsDC1394() override
yarp::dev::ReturnValue getActive(yarp::dev::cameraFeature_id_t feature, bool &isActive) override
Get the current status of the feature, on or off.
FakeFrameGrabber()=default
yarp::dev::ReturnValue getColorCodingMaskDC1394(unsigned int video_mode, unsigned int &val) override
yarp::dev::ReturnValue getFeature(yarp::dev::cameraFeature_id_t feature, double &value) override
Get the current value for the requested feature.
yarp::dev::ReturnValue setOperationModeDC1394(bool b1394b) override
bool open(yarp::os::Searchable &config) override
yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
yarp::dev::ReturnValue getVideoModeMaskDC1394(unsigned int &val) override
FakeFrameGrabber(const FakeFrameGrabber &)=delete
yarp::dev::ReturnValue getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an image from the frame grabber.
yarp::dev::ReturnValue setFeature(yarp::dev::cameraFeature_id_t feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
yarp::dev::ReturnValue setISOSpeedDC1394(int speed) override
yarp::dev::ReturnValue getImageCrop(yarp::dev::cropType_id_t cropType, std::vector< yarp::dev::vertex_t > vertices, yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get a crop of the image from the frame grabber.
yarp::dev::ReturnValue setVideoModeDC1394(int video_mode) override
yarp::dev::ReturnValue getFPSMaskDC1394(unsigned int &val) override
yarp::dev::ReturnValue getMode(yarp::dev::cameraFeature_id_t feature, yarp::dev::FeatureMode &mode) override
Get the current mode for the feature.
void run() override
Main body of the new thread.
void onStop() override
Call-back, called while halting the thread (before join).
yarp::dev::ReturnValue getBytesPerPacketDC1394(unsigned int &bpp) override
yarp::dev::ReturnValue getFPSDC1394(unsigned int &val) override
yarp::dev::ReturnValue setCaptureDC1394(bool bON) override
FakeFrameGrabber(FakeFrameGrabber &&)=delete
yarp::dev::ReturnValue getCameraDescription(yarp::dev::CameraDescriptor &camera) override
Get a basic description of the camera hw.
yarp::dev::ReturnValue getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0) override
yarp::dev::ReturnValue setBroadcastDC1394(bool onoff) override
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::dev::ReturnValue getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep) override
yarp::dev::ReturnValue setColorCodingDC1394(int coding) override
yarp::dev::ReturnValue setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue setOnePush(yarp::dev::cameraFeature_id_t feature) override
Set the requested feature to a value (saturation, brightness ... )
Interface implemented by all device drivers.
Control interface for frame grabber devices that conform to the 1394-based Digital Camera Specificati...
Control interface for frame grabber devices.
An interface for retrieving intrinsic parameter from a rgb camera.
An interface for reading from a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A mini-server for network communication.
Definition Port.h:46
A class for storing options and configuration information.
Definition Property.h:33
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
An abstraction for a thread of execution.
Definition Thread.h:21
Typed image class.
Definition Image.h:603