@@ -39,14 +39,18 @@ namespace libfreenect2
3939static const float depth_q = 0.01 ;
4040static 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