librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

project_point_to_pixel

Open digitologist opened this issue 10 years ago • 1 comments

Dug into the math to undistort the Brown-Conrady distortion and noticed that the operations in project_point_to_pixel don't match project_pixel_to_point.

Point-to-pixel uses...

float f = ...
x *= f;
y *= f;
float dx = x + 2*intrin->coeffs[2]*x*y + intrin->coeffs[3]*(r2 + 2*x*x);
float dy = y + 2*intrin->coeffs[3]*x*y + intrin->coeffs[2]*(r2 + 2*y*y);

...which means the f factor is baked into all parts of dx and dy.

Compare that to project_pixel_to_point:

float f = ...
float ux = x*f + 2*intrin->coeffs[2]*x*y + intrin->coeffs[3]*(r2 + 2*x*x);
float uy = y*f + 2*intrin->coeffs[3]*x*y + intrin->coeffs[2]*(r2 + 2*y*y);

...where the f factor only modifies the first x and y, and which matches how the Brown-Conrady model is usually documented. Why the difference?

digitologist avatar Nov 20 '16 21:11 digitologist

i didn't check the math behind the transformation, but taking a pixel with its depth value and doing a deprojection to point followed by a projection to pixel brings back the pixel values - to some error. Pseudo-code and result:

pixel, depth = [ 240.0 320.0], 0.500696

point = deproject_pixel_to_point(pixel, depth)
>>> [-0.07933103  0.07876374  0.50069648]

pixel = project_point_to_pixel(point)
>>> [ 239.45333862  320.69567871]

So seems to be working.

toinsson avatar Feb 27 '17 17:02 toinsson