OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 18 Oct 2015 11:15:39 -0500initundistortrectifymap line 103 and 137 what is going on?http://answers.opencv.org/question/73533/initundistortrectifymap-line-103-and-137-what-is-going-on/ Hi,
I'm having trouble understanding a line in the original source code of the function initUndistortRectifyMap(..). In the corresponding docs this part doesn't seem to be mentioned.
The code is on line 103 and 137 of the following undistort.cpp function:
[link text](https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/undistort.cpp#L103)
It appears to be taking the product of the camera intrinsic matrix A and multiplying it with the rotation. It then takes the inverses (all on line 103). This is then used on line 137 when bits are extracted out from the result on line 103. The results I get when using this code are excellent but I just can't understand it or tie it into the documentation at:
[link text](http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#initundistortrectifymap)
In particular I don't see how the first three lines of equations in the doc corresspond to the inverse of the cam matrix A and the rotation matrix?
![image description](http://docs.opencv.org/_images/math/8808430360ef87d99c3a5725cd2ba7d2852ba689.png)
Can some clever person put me right or point me at a doc that just explains that bit?
ThanksSun, 18 Oct 2015 06:01:19 -0500http://answers.opencv.org/question/73533/initundistortrectifymap-line-103-and-137-what-is-going-on/Comment by ricor29 for <p>Hi,</p>
<p>I'm having trouble understanding a line in the original source code of the function initUndistortRectifyMap(..). In the corresponding docs this part doesn't seem to be mentioned. </p>
<p>The code is on line 103 and 137 of the following undistort.cpp function:</p>
<p><a href="https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/undistort.cpp#L103">link text</a></p>
<p>It appears to be taking the product of the camera intrinsic matrix A and multiplying it with the rotation. It then takes the inverses (all on line 103). This is then used on line 137 when bits are extracted out from the result on line 103. The results I get when using this code are excellent but I just can't understand it or tie it into the documentation at:</p>
<p><a href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#initundistortrectifymap">link text</a></p>
<p>In particular I don't see how the first three lines of equations in the doc corresspond to the inverse of the cam matrix A and the rotation matrix?</p>
<p><img alt="image description" src="http://docs.opencv.org/_images/math/8808430360ef87d99c3a5725cd2ba7d2852ba689.png"/></p>
<p>Can some clever person put me right or point me at a doc that just explains that bit?
Thanks</p>
http://answers.opencv.org/question/73533/initundistortrectifymap-line-103-and-137-what-is-going-on/?comment=73547#post-id-73547I think I was just being a bit dense and may have an answer after staring at this all afternoon).
I think the documentation is just a more specific case of the implementation in that it doesn't explicitly handle skew in the intrinsic matrix. However the first two equations are just the inverse of the intrinsic matrix (with skew set to zero) and explicitly written out. The third line then handles the rotation. My matrix maths is a bit rusty but I think:
[u v 1]^T = A R [x y 1]^T (camera to pixel coords)
inv(AR) [u v 1]^T = [x y 1]^T (pixel to camera)
inv(R)inv(A) [u v 1]^T = [x y 1]^T
I convinced myself with Matlab and some dummy numbers for fx, fy, cx and cy that inv(A) gives exactly equation 1 and 2. The third equation is just taking care of the inverse of the rotation matrix.Sun, 18 Oct 2015 11:15:39 -0500http://answers.opencv.org/question/73533/initundistortrectifymap-line-103-and-137-what-is-going-on/?comment=73547#post-id-73547