Skip to content

Commit 4cf31d6

Browse files
committed
Merge pull request #397 from Tabjones/master
First prototype of computeCoordinates of point cloud
2 parents 1deb040 + 969a70f commit 4cf31d6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

examples/protonect/include/libfreenect2/registration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class LIBFREENECT2_API Registration
4949
// undistort/register a whole image
5050
void apply(const Frame* rgb, const Frame* depth, Frame* undistorted, Frame* registered, const bool enable_filter = true, Frame* bigdepth = 0) const;
5151

52+
// compute point XYZ RGB from undistored and registered frames
53+
void getPointXYZRGB (const Frame* undistorted, const Frame* registered, int r, int c, float& x, float& y, float& z, float& rgb) const;
54+
5255
private:
5356
void distort(int mx, int my, float& dx, float& dy) const;
5457
void depth_to_color(float mx, float my, float& rx, float& ry) const;

examples/protonect/src/registration.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define _USE_MATH_DEFINES
3030
#include <math.h>
3131
#include <libfreenect2/registration.h>
32+
#include <limits>
3233

3334
namespace libfreenect2
3435
{
@@ -249,6 +250,43 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte
249250
delete[] depth_to_c_off;
250251
}
251252

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*>(&registered_data[512*r+c]);
286+
return;
287+
}
288+
}
289+
252290
Registration::Registration(Freenect2Device::IrCameraParams depth_p, Freenect2Device::ColorCameraParams rgb_p):
253291
depth(depth_p), color(rgb_p), filter_width_half(2), filter_height_half(1), filter_tolerance(0.01f)
254292
{

0 commit comments

Comments
 (0)