OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 06 Nov 2014 07:45:54 -0600How to rescale distortion coefficients for mm unit into OpenCV oneshttp://answers.opencv.org/question/45943/how-to-rescale-distortion-coefficients-for-mm-unit-into-opencv-ones/From the OpenCV documentation I understand that pixel is the unit used to process the distortion effects induced by imperfect objective. As an example in the camera matrix the focal lens must be given in pixel.
On the other hand, I need to use the distortion coefficients k1,k2,p1,p2,k3 provided by the commercial software iWitness for further image processing by means OpenCV. The unit used in iWitness is mm, so that typically k1 is about 1e-04. This mean that Dx = k1r^3, for r=10 mm is 0.1 mm.
I tried to rescale the coefficients to be applied in distance in pixel, that is
k1_OpenCv = k1_iWitness*px_dimension^2, but I get very small k1 value. As an example for Nikon D800, px_dimension = 4.9e-03 mm, so that
k1_OpenCV = 2.4e-09 that is much smaller than the values reported by many users, like 0.1.
Looking at the source of cv::initUndistortRectifyMap it seems that x,y are, in a quite complicated manne,r normalized to size.width size.height respectively. Probably this is the key of the problem, but how to do that correctly?
How to transform (k1,k2,p1,p2,k3)_iWitness in (k1,k2,p1,p2,k3)_OpenCV?
Thanks for any help.Thu, 30 Oct 2014 03:45:09 -0500http://answers.opencv.org/question/45943/how-to-rescale-distortion-coefficients-for-mm-unit-into-opencv-ones/Answer by MMonty1960 for <p>From the OpenCV documentation I understand that pixel is the unit used to process the distortion effects induced by imperfect objective. As an example in the camera matrix the focal lens must be given in pixel.
On the other hand, I need to use the distortion coefficients k1,k2,p1,p2,k3 provided by the commercial software iWitness for further image processing by means OpenCV. The unit used in iWitness is mm, so that typically k1 is about 1e-04. This mean that Dx = k1r^3, for r=10 mm is 0.1 mm.</p>
<p>I tried to rescale the coefficients to be applied in distance in pixel, that is</p>
<p>k1_OpenCv = k1_iWitness*px_dimension^2, but I get very small k1 value. As an example for Nikon D800, px_dimension = 4.9e-03 mm, so that
k1_OpenCV = 2.4e-09 that is much smaller than the values reported by many users, like 0.1. </p>
<p>Looking at the source of cv::initUndistortRectifyMap it seems that x,y are, in a quite complicated manne,r normalized to size.width size.height respectively. Probably this is the key of the problem, but how to do that correctly?</p>
<p>How to transform (k1,k2,p1,p2,k3)_iWitness in (k1,k2,p1,p2,k3)_OpenCV?</p>
<p>Thanks for any help.</p>
http://answers.opencv.org/question/45943/how-to-rescale-distortion-coefficients-for-mm-unit-into-opencv-ones/?answer=46606#post-id-46606Ok perhaps I found the solution: according to the formulae shown in "Camera Calibration and 3D Reconstruction" at OpenCV documentation, the distortion coefficients are applied to dimensionless quantity; in the end the corrected value is multiply to the focal length f.
Therefore, to be used in OpenCV, a correction-coefficient set for millimetre distances should be re-scaled as following:
k1=k1mm*f^2
k2=k2mm*f^4
k3=k3mm*f^6
p1=p1mm*f
p2=p2mm*f
In this way by the undistort function I get pretty images well corrected for distortion.Thu, 06 Nov 2014 07:45:54 -0600http://answers.opencv.org/question/45943/how-to-rescale-distortion-coefficients-for-mm-unit-into-opencv-ones/?answer=46606#post-id-46606