YARP
Yet Another Robot Platform
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>
28
38#ifndef YARP_NO_DEPRECATED // Since YARP 3.5`
39 virtual public yarp::dev::DeviceDriver,
40#else
42#endif
49 public yarp::os::Thread,
51{
52public:
53 FakeFrameGrabber() = default;
58 ~FakeFrameGrabber() override = default;
59
60 bool close() override;
61
79 bool open(yarp::os::Searchable& config) override;
80
81 // yarp::os::PortReader
82 bool read(yarp::os::ConnectionReader& connection) override;
83
84 // yarp::os::Thread
85 void run() override;
86 void onStop() override;
87
88 void timing();
89
90 int height() const override;
91
92 int width() const override;
93 //IRgbVisualParams
94 int getRgbHeight() override;
95
96 int getRgbWidth() override;
97
99
100 bool getRgbResolution(int& width, int& height) override;
101
102 bool setRgbResolution(int width, int height) override;
103
104 bool getRgbFOV(double& horizontalFov, double& verticalFov) override;
105
106 bool setRgbFOV(double horizontalFov, double verticalFov) override;
107
108 bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override;
109
110 bool getRgbMirroring(bool& mirror) override;
111
112 bool setRgbMirroring(bool mirror) override;
113 //
116
117 bool getImageCrop(cropType_id_t cropType,
118 yarp::sig::VectorOf<std::pair<int, int>> vertices,
120 bool getImageCrop(cropType_id_t cropType,
121 yarp::sig::VectorOf<std::pair<int, int>> vertices,
123
125
126 bool hasAudio() override;
127
128 bool hasVideo() override;
129
130 bool hasRawVideo() override;
131
132 bool getCameraDescription(CameraDescriptor *camera) override;
133
134 bool hasFeature(int feature, bool *hasFeature) override;
135
136 bool setFeature(int feature, double value) override;
137
138 bool getFeature(int feature, double *value) override;
139
140 bool setFeature(int feature, double value1, double value2) override;
141
142 bool getFeature(int feature, double *value1, double *value2) override;
143
144 bool hasOnOff(int feature, bool *HasOnOff) override;
145
146 bool setActive(int feature, bool onoff) override;
147
148 bool getActive(int feature, bool *isActive) override;
149
150 bool hasAuto(int feature, bool *hasAuto) override;
151
152 bool hasManual(int feature, bool *hasManual) override;
153
154 bool hasOnePush(int feature, bool *hasOnePush) override;
155
156 bool setMode(int feature, FeatureMode mode) override;
157
158 bool getMode(int feature, FeatureMode *mode) override;
159
160 bool setOnePush(int feature) override;
161
162private:
163 static constexpr size_t default_w = 128;
164 static constexpr size_t default_h = 128;
165 static constexpr size_t default_freq = 30;
166 static constexpr double default_snr = 0.5;
167
168 std::string m_rpcPortName="/fakeFrameGrabber/rpc";
169 yarp::os::Port m_rpcPort;
170
171 size_t ct{0};
172 size_t bx{0};
173 size_t by{0};
174 size_t w{default_w};
175 size_t h{default_h};
176 unsigned long rnd{0};
177 double freq{default_freq};
178 double period{1/freq};
179 double first{0};
180 double horizontalFov{0.0};
181 double verticalFov{0.0};
182 double prev{0};
183 bool have_bg{false};
184 int mode{0};
185 bool add_timestamp{false};
186 bool add_noise{false};
187 double snr{default_snr};
188 bool use_bayer{false};
189 bool use_mono{false};
190 bool mirror{false};
191 bool syncro{false};
192 bool topIsLow{true};
193 yarp::os::Property intrinsic;
195
196 std::random_device rnddev;
197 std::default_random_engine randengine{rnddev()};
198 std::uniform_int_distribution<int> udist{-1, 1};
199 std::uniform_real_distribution<double> ucdist{0.0, 1.0};
200
201 std::mutex curr_buff_mutex;
202 size_t curr_buff{1};
204 bool img_ready[2] {false, false};
205 bool img_consumed[2] {true, true};
206 std::mutex mutex[2]; // FIXME C++17 perhaps use shared_mutex (check if this causes starvation)
207 std::condition_variable img_ready_cv[2];
208 std::condition_variable img_consumed_cv[2];
209 double buff_ts[2];
210
213 yarp::os::Stamp stamp;
214
215 void createTestImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image,
216 double& timestamp);
217
218 bool makeSimpleBayer(yarp::sig::ImageOf<yarp::sig::PixelRgb>& src,
220
221 void printTime(unsigned char* pixbuf, size_t pixbuf_w, size_t pixbuf_h, size_t x, size_t y, char* s, size_t size);
222};
223
224#ifndef YARP_NO_DEPRECATED // Since YARP 3.5
230class TestFrameGrabber :
232 public FakeFrameGrabber
233{
234};
235#endif // YARP_NO_DEPRECATED
236
237#endif // YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
cropType_id_t
fakeFrameGrabber: A fake camera for testing.
int width() const override
Return the width of each frame.
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ... )
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
int getRgbWidth() override
Return the width of each frame.
int getRgbHeight() override
Return the height of each frame.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ... )
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool getActive(int feature, bool *isActive) override
Get the current status of the feature, on or off.
bool hasVideo() override
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
int height() const override
Return the height of each frame.
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool hasAuto(int feature, bool *hasAuto) override
Check if the requested feature has the 'auto' mode.
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
~FakeFrameGrabber() override=default
FakeFrameGrabber & operator=(FakeFrameGrabber &&)=delete
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
FakeFrameGrabber & operator=(const FakeFrameGrabber &)=delete
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
FakeFrameGrabber()=default
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
FakeFrameGrabber(const FakeFrameGrabber &)=delete
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
void run() override
Main body of the new thread.
void onStop() override
Call-back, called while halting the thread (before join).
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an image from the frame grabber.
FakeFrameGrabber(FakeFrameGrabber &&)=delete
bool getImageCrop(cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int > > vertices, yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
bool hasAudio() override
bool hasRawVideo() override
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool close() override
Close the DeviceDriver.
Interface implemented by deprecated device drivers.
Definition: DeviceDriver.h:136
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
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:63
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