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 int height() const override;
82
83 int width() const override;
84 //IRgbVisualParams
85 int getRgbHeight() override;
86
87 int getRgbWidth() override;
88
90
91 bool getRgbResolution(int& width, int& height) override;
92
93 bool setRgbResolution(int width, int height) override;
94
95 bool getRgbFOV(double& horizontalFov, double& verticalFov) override;
96
97 bool setRgbFOV(double horizontalFov, double verticalFov) override;
98
99 bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override;
100
101 bool getRgbMirroring(bool& mirror) override;
102
103 bool setRgbMirroring(bool mirror) override;
104 //
107
108 bool getImageCrop(cropType_id_t cropType,
109 yarp::sig::VectorOf<std::pair<int, int>> vertices,
111 bool getImageCrop(cropType_id_t cropType,
112 yarp::sig::VectorOf<std::pair<int, int>> vertices,
114
116
117 bool hasAudio() override;
118
119 bool hasVideo() override;
120
121 bool hasRawVideo() override;
122
123 bool getCameraDescription(CameraDescriptor *camera) override;
124
125 bool hasFeature(int feature, bool *hasFeature) override;
126
127 bool setFeature(int feature, double value) override;
128
129 bool getFeature(int feature, double *value) override;
130
131 bool setFeature(int feature, double value1, double value2) override;
132
133 bool getFeature(int feature, double *value1, double *value2) override;
134
135 bool hasOnOff(int feature, bool *HasOnOff) override;
136
137 bool setActive(int feature, bool onoff) override;
138
139 bool getActive(int feature, bool *isActive) override;
140
141 bool hasAuto(int feature, bool *hasAuto) override;
142
143 bool hasManual(int feature, bool *hasManual) override;
144
145 bool hasOnePush(int feature, bool *hasOnePush) override;
146
147 bool setMode(int feature, FeatureMode mode) override;
148
149 bool getMode(int feature, FeatureMode *mode) override;
150
151 bool setOnePush(int feature) override;
152
153private:
154 static constexpr size_t default_w = 128;
155 static constexpr size_t default_h = 128;
156 static constexpr size_t default_freq = 30;
157 static constexpr double default_snr = 0.5;
158
159 yarp::os::Port m_rpcPort;
160
161 size_t ct{0};
162 size_t bx{0};
163 size_t by{0};
164 unsigned long rnd{0};
165 double first{0};
166 double prev{0};
167 bool have_bg{false};
168 yarp::os::Property m_intrinsic;
170
171 std::random_device rnddev;
172 std::default_random_engine randengine{rnddev()};
173 std::uniform_int_distribution<int> udist{-1, 1};
174 std::uniform_real_distribution<double> ucdist{0.0, 1.0};
175
176 std::mutex curr_buff_mutex;
177 size_t curr_buff{1};
179 bool img_ready[2] {false, false};
180 bool img_consumed[2] {true, true};
181 std::mutex mutex[2]; // FIXME C++17 perhaps use shared_mutex (check if this causes starvation)
182 std::condition_variable img_ready_cv[2];
183 std::condition_variable img_consumed_cv[2];
184 double buff_ts[2];
185
188 yarp::os::Stamp stamp;
189
190 void createTestImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image,
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#ifndef YARP_NO_DEPRECATED // Since YARP 3.5
205class TestFrameGrabber :
207 public FakeFrameGrabber
208{
209};
210#endif // YARP_NO_DEPRECATED
211
212#endif // YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
cropType_id_t
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.
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
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
Get a crop of the image from the frame grabber.
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.
Interface implemented by all device drivers.
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:605