# Why do we pass R and P to undistortPoints() fcn (calib3d module)?

I have two AVT Manta G125B cameras. I made individual calibrations of the cameras, and then stereo calibration. I am trying to triangulate a point of interest in real-time. I noticed that triangulatePoints() function of calib3d module accepts undistorted image point coordinates as input so I need to use undistortPoints() function to obtain ideal point coordinates. As far as I know, it must be sufficient to pass only cameraMatrix and distCoeffs parameters to undistortPoints. By finding nonlinear least squares solution, undistortPoints() must provide solution. I did not understand why we need to pass R and P (obtained with stereoRectify() fcn) to undistortPoints.

void undistortPoints(InputArray src, OutputArray dst, InputArray cameraMatrix, InputArray distCoeffs, InputArray R=noArray(), InputArray P=noArray())

edit retag close merge delete

"I did not understand why we need to pass R and P" These parameters are optional!

( 2015-03-12 02:49:57 -0600 )edit

I have noticed that they are optional. On the other hand, I already used stereoRectify() fcn and obtained these optional R and P matrices. I did not understand the logic. What is the reason for passing these matrices to undistortPoints()?

( 2015-03-12 08:32:20 -0600 )edit

I haven't given thought to R, but the purpose of the/onw last parameter is to control whether the resulting image coordinates are normalised (i.e. are in the range [-1,1] or not). If your goal is simply to remove the distortion, but still have the points in pixel coordinates with origin at the top left (as it is when you obtain e.g. features with a detector), you would pass your original camera matrix for P. Essentially this argument describes which camera matrix should be valid for the undistorted points. If you leave it blank, the identity matrix is assumed, which is valid for undistorted normalised coordinates.

This is important if you use findEssentialMat and recoverPose which are new in OCV3 which take this parameter as well and it should be equal for all 3 calls.

( 2015-07-13 15:37:00 -0600 )edit