UndistortPoints OpenCV

Dear All,

I have a question regarding OpenCV’s UndistortPoints function…

I have an array which has the following contents:
Count of matches 22
443.424 247.443
573.258 385.409
512.973 255.17
533.048 445.407
434.452 171.801
591.046 378.808
492.866 380.578
572.824 330.274
568.403 469.047
487.081 469.746
607.053 333.272
607.053 333.272
563.119 316.306
521.776 461.68
503.954 374.271
593.78 319.76
466.606 288.315
373.96 259.958
303.708 250.026
567.192 319.702
456.602 333.935
456.602 333.935
These are stored in CvMat* _src …

I calibrated my camera and got an intrinsics and extrinsics xml file.
I ran the cvUndistortPoints(_src,dest,intrinsicmat,extrinsicmat);

the points in dest should be the undistorted locations of the above 2-D points…

However,I receive the following values:

0.16321 -0.0247553
0.397391 0.22356
0.28988 -0.0119857
0.322743 0.332501
0.147593 -0.166145
0.43031 0.211222
0.250384 0.216177
0.397809 0.123595
0.386407 0.374022
0.238701 0.376996
0.461214 0.128059
0.461214 0.128059
0.380234 0.0984338
0.301964 0.361998
0.270643 0.204626
0.436998 0.103836
0.204672 0.0498663
0.0357528 -0.00102099
-0.0946866 -0.0196881
0.387672 0.104507
0.185578 0.13288
0.185578 0.13288

I am in a slump as i think I did everything correctly to the best of my knowledge.Could Anyone point me as to what is wrong with the answer and What would be the correct transformation to get the undistorted points .

I dont know if this is a ratio because the values would be very high(as high as 0.4).

I shall be highly grateful for any answers.

Cheers!
Rahul

the points look all right to me. undistort points moves the points so that the centre of the image is 0,0 and scales everything so that the width and height are both (i think) 1 unit.

Dear Damian ,

Sir,Thank you so much for your reply.

So do you mean that if my image is 640*480

the coordinate locations are :

(320+640*x_value,240+480*y_value);

I think i got the values right because I can see some points while plotting .

Thank you so much ,You have no idea how hard it was for getting this information :slight_smile:

Thank u!

Cheers!
Rahul

Well Eventually I was not able to get it …but …I found this
http://osdir.com/ml/lib.opencv/2005-12/msg00017.html

Hope this could help others …

if i remember well, the undistorted points are relative to the center of the camera lens relative to the sensor (the principal point) and normalized relative to the focal distance in x and y. so the formula to get the point coordinates in the original image are something like:

  
undistorted.x = (x* focalX + principalX);  
undistorted.y = (y* focalY + principalY);  

you can get focalX/Y and principalX/Y from the intrinsics.xml file, which is a 3x3 camera matrix:

fX 0 pX
0 fY pY
0 0 1

in the data tag, ordered like:

  
<data>fx 0 px 0 fy py 0 0 1</data>  

I presume this is the wrong stuff to use then:

  
  
(gdb) p *(float*)distortedIntrinsics.getCameraMatrix().data@9  
$6 = {2.07686121e+27, 4.13200808, 0, 0, 4.13813515e-13, 3.81213689, 0, 0, 2.11765568e-21}  
  

there’s the right numbers of values. but:
a) the matrix isn’t normalised
b) the values are in the wrong place (even transposed)

  
  
2.07686121e+27, 	4.13200808, 		0,   
0,				4.13813515e-13, 	3.81213689,  
0,			 	0,				2.11765568e-21  
  

or is my program just broken :slight_smile:

aha! they’re stored as doubles, which explains all my woes :slight_smile:

  
  
(gdb) p *(double*)undistortedIntrinsics.getCameraMatrix().data@9  
$4 = {708.33033661448769, 0, 319.5, 0, 707.74715921368579, 239.5, 0, 0, 1}  
  

The code in “Opencv-ref-man-2.3.1.pdf” is:
// (u,v) is the input point, (u’, v’) is the output point
// camera_matrix=[fx 0 cx; 0 fy cy; 0 0 1]
// P=[fx’ 0 cx’ tx; 0 fy’ cy’ ty; 0 0 1 tz]
x" = (u - cx)/fx
y" = (v - cy)/fy
(x’,y’) = undistort(x",y",dist_coeffs)
[X,Y,W]T = R*[x’ y’ 1]T
x = X/W, y = Y/W
u’ = x*fx’ + cx’
v’ = y*fy’ + cy’,

I also think the last two lines must be done by the caller.
:wink: