YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeDepthCameraDriver.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
9#include <yarp/os/LogStream.h>
10#include <yarp/os/Value.h>
11
12#include <algorithm>
13#include <map>
14#include <cmath>
15
16using namespace yarp::dev;
17using namespace yarp::sig;
18using namespace yarp::os;
19
20namespace {
21YARP_LOG_COMPONENT(FAKEDEPTHCAMERA, "yarp.device.fakeDepthCamera")
22}
23
27
29
31{
32 if (!this->parseParams(config)) {return false;}
33
35 cfg.fromString(config.toString());
36 cfg.unput("device");
37 cfg.put("device", "fakeFrameGrabber");
38 testgrabber.open(cfg);
39 testgrabber.view(image);
40
41 return true;
42}
43
45{
46 return true;
47}
48
50{
51 return image->height();
52}
53
55{
56 return image->width();
57}
58
60{
61 yCWarning(FAKEDEPTHCAMERA) << "getRgbSupportedConfigurations not implemented yet";
62 return false;
63}
64
65bool FakeDepthCameraDriver::getRgbResolution(int &width, int &height)
66{
67 width = image->width();
68 height = image->height();
69 return true;
70}
71
72bool FakeDepthCameraDriver::setRgbResolution(int width, int height)
73{
74 return false;
75}
76
78{
79 return false;
80}
81
82bool FakeDepthCameraDriver::setRgbFOV(double horizontalFov, double verticalFov)
83{
84 m_rgb_Hfov = horizontalFov;
85 m_rgb_Vfov = verticalFov;
86 return true;
87}
88
89bool FakeDepthCameraDriver::setDepthFOV(double horizontalFov, double verticalFov)
90{
91 m_dep_Hfov = horizontalFov;
92 m_dep_Vfov = verticalFov;
93 return true;
94}
95
101
102bool FakeDepthCameraDriver::getRgbFOV(double &horizontalFov, double &verticalFov)
103{
104 horizontalFov = m_rgb_Hfov;
105 verticalFov = m_rgb_Vfov;
106 return false;
107}
108
110{
111 mirror = false;
112 return true;
113}
114
116{
117 return false;
118}
119
121{
122 intrinsic.put("physFocalLength", 0.5);
123 intrinsic.put("focalLengthX", 512);
124 intrinsic.put("focalLengthY", 512);
125 intrinsic.put("principalPointX", 235);
126 intrinsic.put("principalPointY", 231);
127 intrinsic.put("distortionModel", "plumb_bob");
128 intrinsic.put("k1", 0);
129 intrinsic.put("k2", 0);
130 intrinsic.put("t1", 0);
131 intrinsic.put("t2", 0);
132 intrinsic.put("k3", 0);
133
134 intrinsic.put("stamp", yarp::os::Time::now());
135 return true;
136}
137
139{
140 return image->height();
141}
142
144{
145 return image->width();
146}
147
148bool FakeDepthCameraDriver::getDepthFOV(double& horizontalFov, double& verticalFov)
149{
150 horizontalFov = m_dep_Hfov;
151 verticalFov = m_dep_Vfov;
152 return false;
153}
154
156{
157 intrinsic.put("physFocalLength", 0.5);
158 intrinsic.put("focalLengthX", 512);
159 intrinsic.put("focalLengthY", 512);
160 intrinsic.put("principalPointX", 235);
161 intrinsic.put("principalPointY", 231);
162 intrinsic.put("distortionModel", "plumb_bob");
163 intrinsic.put("k1", 0);
164 intrinsic.put("k2", 0);
165 intrinsic.put("t1", 0);
166 intrinsic.put("t2", 0);
167 intrinsic.put("k3", 0);
168
169 intrinsic.put("stamp", yarp::os::Time::now());
170 return true;
171}
172
177
179{
182 return true;
183}
184
186{
189 return true;
190}
191
193{
194 mirror = false;
195 return true;
196}
197
199{
200 return false;
201}
202
204{
205 extrinsic.resize(4, 4);
206 extrinsic.zero();
207
208 extrinsic[0][0] = 1;
209 extrinsic[1][1] = 1;
210 extrinsic[2][2] = 1;
211 extrinsic[3][3] = 1;
212 return true;
213}
214
216{
217 if (!image->getImage(imageof)) {return false;}
218 rgbImage.setPixelCode(VOCAB_PIXEL_RGB);
219 rgbImage.resize(imageof);
220 memcpy((void*)rgbImage.getRawImage(), (void*)imageof.getRawImage(), imageof.getRawImageSize());
221 if (timeStamp) {
222 timeStamp->update(yarp::os::Time::now());
223 }
224 return true;
225}
226
228{
229 if (!image->getImage(imageof)) {return false;}
230 depthImage.resize(imageof);
231 for (size_t i = 0; i < imageof.width(); i++)
232 {
233 for (size_t j = 0; j < imageof.height(); j++)
234 {
235 PixelRgb pix = (*(PixelRgb*)imageof.getPixelAddress(i, j));
236 *(PixelFloat*)depthImage.getPixelAddress(i, j) = (float(pix.b) / 255.0)/3.0 + (float(pix.g) / 255.0) / 3.0 + (float(pix.r) / 255.0) / 3.0;
237 }
238 }
239 if (timeStamp) {
240 timeStamp->update(yarp::os::Time::now());
241 }
242 return true;
243}
244
246{
247 return getRgbImage(colorFrame, colorStamp) & getDepthImage(depthFrame, depthStamp);
248}
249
254
256{
257 return "no error";
258}
@ VOCAB_PIXEL_RGB
Definition Image.h:44
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
int getDepthWidth() override
Return the height of each frame.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
bool getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
int getRgbHeight() override
Return the height of each frame.
double getDepthAccuracy() override
Get the minimum detectable variation in distance [meter].
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getDepthImage(depthImage &depthImage, Stamp *timeStamp=nullptr) override
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool getRgbImage(FlexImage &rgbImage, Stamp *timeStamp=nullptr) override
Get the rgb frame from the device.
std::string getLastErrorMsg(Stamp *timeStamp=nullptr) override
Return an error message in case of error.
int getDepthHeight() override
Return the height of each frame.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool getDepthIntrinsicParam(Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
RGBDSensor_status getSensorStatus() override
Get the surrent status of the sensor, using enum type.
bool getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
bool getImages(FlexImage &colorFrame, depthImage &depthFrame, Stamp *colorStamp=nullptr, Stamp *depthStamp=nullptr) override
bool setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
bool getRgbIntrinsicParam(Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool close() override
Close the DeviceDriver.
~FakeDepthCameraDriver() override
bool getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
bool setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
int getRgbWidth() override
Return the width of each frame.
bool setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
bool view(T *&x)
Get an interface to the device driver.
virtual int width() const =0
Return the width of each frame.
virtual int height() const =0
Return the height of each frame.
virtual bool getImage(ImageType &image)=0
Get an image from the frame grabber.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
Definition Stamp.cpp:124
Image class with user control of representation details.
Definition Image.h:363
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:479
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
Definition Image.cpp:488
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:402
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
unsigned char * getPixelAddress(size_t x, size_t y) const
Get address of a pixel in memory.
Definition Image.h:245
A class for a Matrix.
Definition Matrix.h:39
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
An interface to the operating system, including Port based communication.