MCPcopy Create free account
hub / github.com/OpenKinect/libfreenect2 / undistort

Method undistort

src/libfreenect2.cpp:160–205  ·  view source on GitHub ↗

The inverse of distort() using Newton's method Return true if converged correctly This function considers tangential distortion with double precision.

Source from the content-addressed store, hash-verified

158 //Return true if converged correctly
159 //This function considers tangential distortion with double precision.
160 bool undistort(double x, double y, double &xu, double &yu) const
161 {
162 double x0 = x;
163 double y0 = y;
164
165 double last_x = x;
166 double last_y = y;
167 const int max_iterations = 100;
168 int iter;
169 for (iter = 0; iter < max_iterations; iter++) {
170 double x2 = x*x;
171 double y2 = y*y;
172 double x2y2 = x2 + y2;
173 double x2y22 = x2y2*x2y2;
174 double x2y23 = x2y2*x2y22;
175
176 //Jacobian matrix
177 double Ja = k3*x2y23 + (k2+6*k3*x2)*x2y22 + (k1+4*k2*x2)*x2y2 + 2*k1*x2 + 6*p2*x + 2*p1*y + 1;
178 double Jb = 6*k3*x*y*x2y22 + 4*k2*x*y*x2y2 + 2*k1*x*y + 2*p1*x + 2*p2*y;
179 double Jc = Jb;
180 double Jd = k3*x2y23 + (k2+6*k3*y2)*x2y22 + (k1+4*k2*y2)*x2y2 + 2*k1*y2 + 2*p2*x + 6*p1*y + 1;
181
182 //Inverse Jacobian
183 double Jdet = 1/(Ja*Jd - Jb*Jc);
184 double a = Jd*Jdet;
185 double b = -Jb*Jdet;
186 double c = -Jc*Jdet;
187 double d = Ja*Jdet;
188
189 double f, g;
190 distort(x, y, f, g);
191 f -= x0;
192 g -= y0;
193
194 x -= a*f + b*g;
195 y -= c*f + d*g;
196 const double eps = std::numeric_limits<double>::epsilon()*16;
197 if (fabs(x - last_x) <= eps && fabs(y - last_y) <= eps)
198 break;
199 last_x = x;
200 last_y = y;
201 }
202 xu = x;
203 yu = y;
204 return iter < max_iterations;
205 }
206};
207
208/** Freenect2 device implementation. */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected