Skip to content

Commit 1cdb323

Browse files
committed
add missing transformation to depth camera coordinates
1 parent d3b9d8f commit 1cdb323

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

examples/protonect/include/libfreenect2/registration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LIBFREENECT2_API Registration
4242
void apply( int dx, int dy, float dz, float& cx, float &cy);
4343

4444
private:
45-
void undistort_depth(float dx, float dy, float& mx, float& my);
45+
void undistort_depth(int dx, int dy, float& mx, float& my);
4646
void depth_to_color(float mx, float my, float& rx, float& ry);
4747

4848
protocol::DepthCameraParamsResponse *depth;

examples/protonect/src/registration.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ namespace libfreenect2
3939
static const float depth_q = 0.01;
4040
static const float color_q = 0.002199;
4141

42-
void Registration::undistort_depth(float dx, float dy, float& mx, float& my)
42+
void Registration::undistort_depth(int x, int y, float& mx, float& my)
4343
{
44+
float dx = ((float)x - depth->cx) / depth->fx;
45+
float dy = ((float)y - depth->cy) / depth->fy;
46+
4447
float ps = (dx * dx) + (dy * dy);
4548
float qs = ((ps * depth->k3 + depth->k2) * ps + depth->k1) * ps + 1.0;
4649
for (int i = 0; i < 9; i++) {
4750
float qd = ps / (qs * qs);
4851
qs = ((qd * depth->k3 + depth->k2) * qd + depth->k1) * qd + 1.0;
4952
}
53+
5054
mx = dx / qs;
5155
my = dy / qs;
5256
}
@@ -87,24 +91,21 @@ Registration::Registration(protocol::DepthCameraParamsResponse *depth_p, protoco
8791
depth(depth_p), color(rgb_p)
8892
{
8993
float mx, my;
90-
int rx, ry;
94+
float rx, ry;
9195

9296
for (int x = 0; x < 512; x++)
9397
for (int y = 0; y < 424; y++) {
9498
undistort_depth(x,y,mx,my);
95-
rx = round(mx);
96-
ry = round(my);
97-
undistort_map[rx][ry][0] = x;
98-
undistort_map[rx][ry][1] = y;
99+
undistort_map[x][y][0] = mx;
100+
undistort_map[x][y][1] = my;
99101
}
100102

101103
for (int x = 0; x < 512; x++)
102104
for (int y = 0; y < 424; y++) {
103-
depth_to_color(x,y,mx,my);
104-
rx = round(mx);
105-
ry = round(my);
106-
depth_to_color_map[rx][ry][0] = x;
107-
depth_to_color_map[rx][ry][1] = y;
105+
undistort_depth(x,y,mx,my);
106+
depth_to_color(mx,my,rx,ry);
107+
depth_to_color_map[x][y][0] = rx;
108+
depth_to_color_map[x][y][1] = ry;
108109
}
109110
}
110111

0 commit comments

Comments
 (0)