YARP
Yet Another Robot Platform
FakeFrameGrabber.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  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
11 #define YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
12 
13 
14 #include <yarp/sig/ImageFile.h>
15 #include <yarp/dev/DeviceDriver.h>
19 #include <yarp/os/Searchable.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/os/Vocab.h>
22 #include <yarp/os/Log.h>
23 #include <yarp/os/Value.h>
24 #include <yarp/dev/IVisualParams.h>
25 
26 #include <cstdio>
27 #include <random>
28 
44 {
45 public:
46  FakeFrameGrabber() = default;
51  ~FakeFrameGrabber() override = default;
52 
53  bool close() override;
54 
71  bool open(yarp::os::Searchable& config) override;
72 
73  void timing();
74 
75  int height() const override;
76 
77  int width() const override;
78  //IRgbVisualParams
79  int getRgbHeight() override;
80 
81  int getRgbWidth() override;
82 
84 
85  bool getRgbResolution(int& width, int& height) override;
86 
87  bool setRgbResolution(int width, int height) override;
88 
89  bool getRgbFOV(double& horizontalFov, double& verticalFov) override;
90 
91  bool setRgbFOV(double horizontalFov, double verticalFov) override;
92 
93  bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override;
94 
95  bool getRgbMirroring(bool& mirror) override;
96 
97  bool setRgbMirroring(bool mirror) override;
98  //
100 
102 
104 
105  bool hasAudio() override;
106 
107  bool hasVideo() override;
108 
109  bool hasRawVideo() override;
110 
111  bool getCameraDescription(CameraDescriptor *camera) override;
112 
113  bool hasFeature(int feature, bool *hasFeature) override;
114 
115  bool setFeature(int feature, double value) override;
116 
117  bool getFeature(int feature, double *value) override;
118 
119  bool setFeature(int feature, double value1, double value2) override;
120 
121  bool getFeature(int feature, double *value1, double *value2) override;
122 
123  bool hasOnOff(int feature, bool *HasOnOff) override;
124 
125  bool setActive(int feature, bool onoff) override;
126 
127  bool getActive(int feature, bool *isActive) override;
128 
129  bool hasAuto(int feature, bool *hasAuto) override;
130 
131  bool hasManual(int feature, bool *hasManual) override;
132 
133  bool hasOnePush(int feature, bool *hasOnePush) override;
134 
135  bool setMode(int feature, FeatureMode mode) override;
136 
137  bool getMode(int feature, FeatureMode *mode) override;
138 
139  bool setOnePush(int feature) override;
140 
141 private:
142  static constexpr size_t default_w = 128;
143  static constexpr size_t default_h = 128;
144  static constexpr size_t default_freq = 30;
145 
146  size_t ct{0};
147  size_t bx{0};
148  size_t by{0};
149  size_t w{default_w};
150  size_t h{default_h};
151  unsigned long rnd{0};
152  double freq{default_freq};
153  double period{1/freq};
154  double first{0};
155  double horizontalFov{0.0};
156  double verticalFov{0.0};
157  double prev{0};
158  bool have_bg{false};
159  int mode{0};
160  bool use_bayer{false};
161  bool use_mono{false};
162  bool mirror{false};
163  yarp::os::Property intrinsic;
165 
166  std::random_device rnddev;
167  std::default_random_engine randengine{rnddev()};
168  std::uniform_int_distribution<int> udist{-1, 1};
169 
172  yarp::os::Stamp stamp;
173 
174  void createTestImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image);
175 
176  bool makeSimpleBayer(yarp::sig::ImageOf<yarp::sig::PixelRgb>& src,
178 
179  void printTime(unsigned char* pixbuf, size_t pixbuf_w, size_t pixbuf_h, size_t x, size_t y, char* s, size_t size);
180 };
181 
182 
184 {
185 public:
186  bool open(yarp::os::Searchable& config) override;
187 };
188 
189 
199 #endif // YARP_FAKEFRAMEGRABBER_FAKEFRAMEGRABBER_H
define common interfaces to discover remote camera capabilities
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
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.
FakeFrameGrabber & operator=(FakeFrameGrabber &&)=delete
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.
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.
FakeFrameGrabber(FakeFrameGrabber &&)=delete
bool hasAudio() override
bool hasRawVideo() override
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Control interface for frame grabber devices.
Read a YARP-format image from a device.
Read a YARP-format image from a device.
An interface for retrieving intrinsic parameter from a rgb camera.
Definition: IVisualParams.h:73
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