YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeDepthCameraDriver_mini.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_mini")
22}
23
27
29
31{
32 yCDebug(FAKEDEPTHCAMERA) << "Opening Device";
33 if (!this->parseParams(config)) {return false;}
34
37 return true;
38}
39
41{
42 yCDebug(FAKEDEPTHCAMERA) << "Closing Device";
43 std::lock_guard <std::recursive_mutex> lg(m_mutex);
44 return true;
45}
46
48{
49 std::lock_guard <std::recursive_mutex> lg(m_mutex);
50 return m_rgb_h;
51}
52
54{
55 std::lock_guard <std::recursive_mutex> lg(m_mutex);
56 return m_rgb_w;
57}
58
60{
61 std::lock_guard <std::recursive_mutex> lg(m_mutex);
63 configurations.push_back(cfg);
64 return ReturnValue_ok;
65}
66
68{
69 std::lock_guard <std::recursive_mutex> lg(m_mutex);
70 width = m_rgb_w;
71 height = m_rgb_h;
72 return ReturnValue_ok;
73}
74
76{
77 std::lock_guard <std::recursive_mutex> lg(m_mutex);
82 for (size_t y = 0; y < m_rgb_h; y++)
83 for (size_t x = 0; x < m_rgb_w; x++)
84 {
85 rgbImg.pixel(x, y).r = x * 255.0 / m_rgb_w;
86 rgbImg.pixel(x, y).g = 0;
87 rgbImg.pixel(x, y).b = y * 255.0 / m_rgb_h;
88 }
89}
90
92{
93 std::lock_guard <std::recursive_mutex> lg(m_mutex);
95 size_t totalPixels = m_dep_w * m_dep_h;
96 size_t index = 0;
97 for (size_t y = 0; y < m_dep_h; y++)
98 for (size_t x = 0; x < m_dep_w; x++) {
99 auto& p = m_depthImage.pixel(x, y);
100 p = static_cast<double>(index) / (totalPixels - 1);
101 ++index;
102 }
103}
104
106{
107 std::lock_guard <std::recursive_mutex> lg(m_mutex);
108 m_rgb_w = width;
109 m_rgb_h = height;
111 return ReturnValue_ok;
112}
113
115{
116 std::lock_guard <std::recursive_mutex> lg(m_mutex);
117 width = m_dep_w;
118 height = m_dep_h;
119 return ReturnValue_ok;
120}
121
123{
124 std::lock_guard <std::recursive_mutex> lg(m_mutex);
125 m_dep_w = width;
126 m_dep_h = height;
128 return ReturnValue_ok;
129}
130
131ReturnValue FakeDepthCameraDriver_mini::setRgbFOV(double horizontalFov, double verticalFov)
132{
133 std::lock_guard <std::recursive_mutex> lg(m_mutex);
134 m_rgb_Hfov = horizontalFov;
135 m_rgb_Vfov = verticalFov;
136 return ReturnValue_ok;
137}
138
139ReturnValue FakeDepthCameraDriver_mini::setDepthFOV(double horizontalFov, double verticalFov)
140{
141 std::lock_guard <std::recursive_mutex> lg(m_mutex);
142 m_dep_Hfov = horizontalFov;
143 m_dep_Vfov = verticalFov;
144 return ReturnValue_ok;
145}
146
148{
149 std::lock_guard <std::recursive_mutex> lg(m_mutex);
151 return ReturnValue_ok;
152}
153
154ReturnValue FakeDepthCameraDriver_mini::getRgbFOV(double& horizontalFov, double& verticalFov)
155{
156 std::lock_guard <std::recursive_mutex> lg(m_mutex);
157 horizontalFov = m_rgb_Hfov;
158 verticalFov = m_rgb_Vfov;
159 return ReturnValue_ok;
160}
161
163{
164 std::lock_guard <std::recursive_mutex> lg(m_mutex);
165 mirror = m_rgb_mirror;
166 return ReturnValue_ok;
167}
168
170{
171 std::lock_guard <std::recursive_mutex> lg(m_mutex);
172 m_rgb_mirror = mirror;
173 return ReturnValue_ok;
174}
175
177{
178 std::lock_guard <std::recursive_mutex> lg(m_mutex);
179 intrinsic.put("physFocalLength", 0.5);
180 intrinsic.put("focalLengthX", 512);
181 intrinsic.put("focalLengthY", 512);
182 intrinsic.put("principalPointX", 235);
183 intrinsic.put("principalPointY", 231);
184 intrinsic.put("distortionModel", "plumb_bob");
185 intrinsic.put("k1", 0);
186 intrinsic.put("k2", 0);
187 intrinsic.put("t1", 0);
188 intrinsic.put("t2", 0);
189 intrinsic.put("k3", 0);
190
191 intrinsic.put("stamp", yarp::os::Time::now());
192 return ReturnValue_ok;
193}
194
196{
197 std::lock_guard <std::recursive_mutex> lg(m_mutex);
198 return m_dep_h;
199}
200
202{
203 std::lock_guard <std::recursive_mutex> lg(m_mutex);
204 return m_dep_w;
205}
206
207ReturnValue FakeDepthCameraDriver_mini::getDepthFOV(double& horizontalFov, double& verticalFov)
208{
209 std::lock_guard <std::recursive_mutex> lg(m_mutex);
210 horizontalFov = m_dep_Hfov;
211 verticalFov = m_dep_Vfov;
212 return ReturnValue_ok;
213}
214
216{
217 std::lock_guard <std::recursive_mutex> lg(m_mutex);
218 intrinsic.put("physFocalLength", 0.5);
219 intrinsic.put("focalLengthX", 512);
220 intrinsic.put("focalLengthY", 512);
221 intrinsic.put("principalPointX", 235);
222 intrinsic.put("principalPointY", 231);
223 intrinsic.put("distortionModel", "plumb_bob");
224 intrinsic.put("k1", 0);
225 intrinsic.put("k2", 0);
226 intrinsic.put("t1", 0);
227 intrinsic.put("t2", 0);
228 intrinsic.put("k3", 0);
229
230 intrinsic.put("stamp", yarp::os::Time::now());
231 return ReturnValue_ok;
232}
233
235{
236 std::lock_guard <std::recursive_mutex> lg(m_mutex);
238 return ReturnValue_ok;
239}
240
242{
243 std::lock_guard <std::recursive_mutex> lg(m_mutex);
244 nearPlane = m_dep_near;
245 farPlane = m_dep_far;
246 return ReturnValue_ok;
247}
248
250{
251 std::lock_guard <std::recursive_mutex> lg(m_mutex);
252 m_dep_near = nearPlane;
253 m_dep_far = farPlane;
254 return ReturnValue_ok;
255}
256
258{
259 std::lock_guard <std::recursive_mutex> lg(m_mutex);
260 mirror = m_depth_mirror;
261 return ReturnValue_ok;
262}
263
265{
266 std::lock_guard <std::recursive_mutex> lg(m_mutex);
268 return ReturnValue_ok;
269}
270
272{
273 std::lock_guard <std::recursive_mutex> lg(m_mutex);
274 extrinsic.resize(4, 4);
275 extrinsic.zero();
276
277 extrinsic[0][0] = 1;
278 extrinsic[1][1] = 1;
279 extrinsic[2][2] = 1;
280 extrinsic[3][3] = 1;
281 return ReturnValue_ok;
282}
283
285{
286 std::lock_guard <std::recursive_mutex> lg(m_mutex);
288 if (timeStamp) {
289 timeStamp->update(yarp::os::Time::now());
290 }
291 return ReturnValue_ok;
292}
293
295{
296 std::lock_guard <std::recursive_mutex> lg(m_mutex);
298 if (timeStamp) {
299 timeStamp->update(yarp::os::Time::now());
300 }
301 return ReturnValue_ok;
302}
303
305{
306 std::lock_guard <std::recursive_mutex> lg(m_mutex);
307 auto r1 = getRgbImage(colorFrame, colorStamp);
308 auto r2 = getDepthImage(depthFrame, depthStamp);
309 ReturnValue rr = r1 && r2;
310 return rr;
311}
312
314{
315 std::lock_guard <std::recursive_mutex> lg(m_mutex);
316 status = RGBD_SENSOR_OK_IN_USE;
317 return ReturnValue_ok;
318}
319
321{
322 std::lock_guard <std::recursive_mutex> lg(m_mutex);
323 msg = std::string("no error");
324 return ReturnValue_ok;
325}
@ VOCAB_PIXEL_RGB
Definition Image.h:44
#define ReturnValue_ok
Definition ReturnValue.h:80
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
yarp::dev::ReturnValue getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
yarp::dev::ReturnValue getDepthIntrinsicParam(Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
int getDepthWidth() override
Return the height of each frame.
yarp::dev::ReturnValue getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
yarp::dev::ReturnValue getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
yarp::dev::ReturnValue setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
yarp::dev::ReturnValue getLastErrorMsg(std::string &mesg, Stamp *timeStamp=nullptr) override
Return an error message in case of error.
yarp::dev::ReturnValue getRgbIntrinsicParam(Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
int getRgbWidth() override
Return the width of each frame.
int getDepthHeight() override
Return the height of each frame.
yarp::dev::ReturnValue getImages(FlexImage &colorFrame, depthImage &depthFrame, Stamp *colorStamp=nullptr, Stamp *depthStamp=nullptr) override
yarp::dev::ReturnValue getDepthAccuracy(double &accuracy) override
Get the minimum detectable variation in distance [meter].
yarp::dev::ReturnValue getDepthResolution(int &width, int &height) override
Get the resolution of the depth image from the camera.
yarp::dev::ReturnValue getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
int getRgbHeight() override
Return the height of each frame.
yarp::dev::ReturnValue setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
~FakeDepthCameraDriver_mini() override
yarp::dev::ReturnValue setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
yarp::dev::ReturnValue getDepthImage(depthImage &depthImage, Stamp *timeStamp=nullptr) override
yarp::dev::ReturnValue setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
yarp::dev::ReturnValue getSensorStatus(RGBDSensor_status &status) override
yarp::dev::ReturnValue getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
yarp::dev::ReturnValue getRgbImage(FlexImage &rgbImage, Stamp *timeStamp=nullptr) override
Get the rgb frame from the device.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
yarp::dev::ReturnValue setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
Struct describing a possible camera configuration.
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
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:361
void setQuantum(size_t imgQuantum)
Definition Image.h:376
void setPixelCode(int imgPixelCode)
Definition Image.h:364
T & pixel(size_t x, size_t y)
Definition Image.h:619
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:387
A class for a Matrix.
Definition Matrix.h:39
#define yCDebug(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.
constexpr char accuracy[]