|
29 | 29 | #define _USE_MATH_DEFINES
|
30 | 30 | #include <math.h>
|
31 | 31 | #include <libfreenect2/registration.h>
|
| 32 | +#include <limits> |
32 | 33 |
|
33 | 34 | namespace libfreenect2
|
34 | 35 | {
|
@@ -249,6 +250,43 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte
|
249 | 250 | delete[] depth_to_c_off;
|
250 | 251 | }
|
251 | 252 |
|
| 253 | +/** |
| 254 | + * Computes Euclidean coordinates of a pixel and its color from already registered |
| 255 | + * depth and color frames. I.e. constructs a point to fill a point cloud. |
| 256 | + * @param undistorted Undistorted depth frame from Registration::apply. |
| 257 | + * @param registered Registered color frame from Registration::apply. |
| 258 | + * @param r row index of depth frame this point belong to. |
| 259 | + * @param c column index of depth frame this point belong to. |
| 260 | + * @param[out] x x coordinate of point. |
| 261 | + * @param[out] y y coordinate of point. |
| 262 | + * @param[out] z z coordinate of point. |
| 263 | + * @param[out] RGB associated rgb color of point. |
| 264 | + */ |
| 265 | +void Registration::getPointXYZRGB (const Frame* undistorted, const Frame* registered, int r, int c, float& x, float& y, float& z, float& rgb) const |
| 266 | +{ |
| 267 | + const float bad_point = std::numeric_limits<float>::quiet_NaN(); |
| 268 | + const float cx(depth.cx), cy(depth.cy); |
| 269 | + const float fx(1/depth.fx), fy(1/depth.fy); |
| 270 | + float* undistorted_data = (float *)undistorted->data; |
| 271 | + float* registered_data = (float *)registered->data; |
| 272 | + const float depth_val = undistorted_data[512*r+c]/1000.0f; //scaling factor, so that value of 1 is one meter. |
| 273 | + if (isnan(depth_val) || depth_val <= 0.001) |
| 274 | + { |
| 275 | + //depth value is not valid |
| 276 | + x = y = z = bad_point; |
| 277 | + rgb = 0; |
| 278 | + return; |
| 279 | + } |
| 280 | + else |
| 281 | + { |
| 282 | + x = (c + 0.5 - cx) * fx * depth_val; |
| 283 | + y = (r + 0.5 - cy) * fy * depth_val; |
| 284 | + z = depth_val; |
| 285 | + rgb = *reinterpret_cast<float*>(®istered_data[512*r+c]); |
| 286 | + return; |
| 287 | + } |
| 288 | +} |
| 289 | + |
252 | 290 | Registration::Registration(Freenect2Device::IrCameraParams depth_p, Freenect2Device::ColorCameraParams rgb_p):
|
253 | 291 | depth(depth_p), color(rgb_p), filter_width_half(2), filter_height_half(1), filter_tolerance(0.01f)
|
254 | 292 | {
|
|
0 commit comments