Skip to content

Commit 8ae30fd

Browse files
committed
store local copy of camera params
1 parent 1cdb323 commit 8ae30fd

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

examples/protonect/include/libfreenect2/registration.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class LIBFREENECT2_API Registration
4545
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

48-
protocol::DepthCameraParamsResponse *depth;
49-
protocol::RgbCameraParamsResponse *color;
48+
protocol::DepthCameraParamsResponse depth;
49+
protocol::RgbCameraParamsResponse color;
5050

5151
float undistort_map[512][424][2];
5252
float depth_to_color_map[512][424][2];

examples/protonect/src/registration.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ static const float color_q = 0.002199;
4141

4242
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;
44+
float dx = ((float)x - depth.cx) / depth.fx;
45+
float dy = ((float)y - depth.cy) / depth.fy;
4646

4747
float ps = (dx * dx) + (dy * dy);
48-
float qs = ((ps * depth->k3 + depth->k2) * ps + depth->k1) * ps + 1.0;
48+
float qs = ((ps * depth.k3 + depth.k2) * ps + depth.k1) * ps + 1.0;
4949
for (int i = 0; i < 9; i++) {
5050
float qd = ps / (qs * qs);
51-
qs = ((qd * depth->k3 + depth->k2) * qd + depth->k1) * qd + 1.0;
51+
qs = ((qd * depth.k3 + depth.k2) * qd + depth.k1) * qd + 1.0;
5252
}
5353

5454
mx = dx / qs;
@@ -57,38 +57,38 @@ void Registration::undistort_depth(int x, int y, float& mx, float& my)
5757

5858
void Registration::depth_to_color(float mx, float my, float& rx, float& ry)
5959
{
60-
mx *= depth->fx * depth_q;
61-
my *= depth->fy * depth_q;
60+
mx *= depth.fx * depth_q;
61+
my *= depth.fy * depth_q;
6262

6363
float wx =
64-
(mx * mx * mx * color->mx_x3y0) + (my * my * my * color->mx_x0y3) +
65-
(mx * mx * my * color->mx_x2y1) + (my * my * mx * color->mx_x1y2) +
66-
(mx * mx * color->mx_x2y0) + (my * my * color->mx_x0y2) + (mx * my * color->mx_x1y1) +
67-
(mx * color->mx_x1y0) + (my * color->mx_x0y1) + (color->mx_x0y0);
64+
(mx * mx * mx * color.mx_x3y0) + (my * my * my * color.mx_x0y3) +
65+
(mx * mx * my * color.mx_x2y1) + (my * my * mx * color.mx_x1y2) +
66+
(mx * mx * color.mx_x2y0) + (my * my * color.mx_x0y2) + (mx * my * color.mx_x1y1) +
67+
(mx * color.mx_x1y0) + (my * color.mx_x0y1) + (color.mx_x0y0);
6868

6969
float wy =
70-
(mx * mx * mx * color->my_x3y0) + (my * my * my * color->my_x0y3) +
71-
(mx * mx * my * color->my_x2y1) + (my * my * mx * color->my_x1y2) +
72-
(mx * mx * color->my_x2y0) + (my * my * color->my_x0y2) + (mx * my * color->my_x1y1) +
73-
(mx * color->my_x1y0) + (my * color->my_x0y1) + (color->my_x0y0);
70+
(mx * mx * mx * color.my_x3y0) + (my * my * my * color.my_x0y3) +
71+
(mx * mx * my * color.my_x2y1) + (my * my * mx * color.my_x1y2) +
72+
(mx * mx * color.my_x2y0) + (my * my * color.my_x0y2) + (mx * my * color.my_x1y1) +
73+
(mx * color.my_x1y0) + (my * color.my_x0y1) + (color.my_x0y0);
7474

75-
rx = wx / (color->color_f * color_q);
76-
ry = wy / (color->color_f * color_q);
75+
rx = wx / (color.color_f * color_q);
76+
ry = wy / (color.color_f * color_q);
7777
}
7878

7979
void Registration::apply( int dx, int dy, float dz, float& cx, float &cy)
8080
{
8181
float rx = depth_to_color_map[dx][dy][0];
8282
float ry = depth_to_color_map[dx][dy][1];
8383

84-
rx += (color->shift_m / dz) - (color->shift_m / color->shift_d);
84+
rx += (color.shift_m / dz) - (color.shift_m / color.shift_d);
8585

86-
cx = rx * color->color_f + color->color_cx;
87-
cy = ry * color->color_f + color->color_cy;
86+
cx = rx * color.color_f + color.color_cx;
87+
cy = ry * color.color_f + color.color_cy;
8888
}
8989

9090
Registration::Registration(protocol::DepthCameraParamsResponse *depth_p, protocol::RgbCameraParamsResponse *rgb_p):
91-
depth(depth_p), color(rgb_p)
91+
depth(*depth_p), color(*rgb_p)
9292
{
9393
float mx, my;
9494
float rx, ry;

0 commit comments

Comments
 (0)