what is new camera matrix in cvundistortpoints.?
Asked Answered
H

2

6

I am facing a problem in understanding what the new camera matrix in cvUndistortpoints. We get a camera matrix of camera in stereocalibration itself and why we have to pass a new cameramatrix in cvstereorectify which we obtain from cvundistortpoints. How exactly new camera matrix different from camera matrix after the output of cvUndistortPoints?

void cvUndistortPoints(const CvMat* src, CvMat* dst, const CvMat* cameraMatrix, 
         const CvMat* distCoeffs, const CvMat* R=NULL, const CvMat* P=NULL)

The reference link is here: https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga55c716492470bfe86b0ee9bf3a1f0f7e

Heddie answered 27/5, 2012 at 11:28 Comment(1)
Actually, P, the new camera matrix, is an -input-. cvUndistortPoints does not create it.Crankshaft
C
3

The answer is one page up in the documentation you provided. P is given to you by StereoRectify.

Here is what it says about it under undistort in opencvrefman.pdf, which, my friend, you should be reading too:

newCameraMatrix – Camera matrix of the distorted image. By default, it is the same as cameraMatrix but you may additionally scale and shift the result by using a different matrix.

Now, I am pretty new to this, and have not had occasion to use the StereoRectify functions yet, but I am guessing that you might want to undistort an image to look like what a different camera would see.

Crankshaft answered 27/5, 2012 at 14:23 Comment(2)
I would be very happy if you could clarify me, why we transfer the new camera matrix into cvUndistortpoints. What is the specific use in passing this new matrix..Heddie
The confusing part in the documentation is the phrase "camera matrix of the distorted image". It's NOT the matrix of the distorted image, but of the hypothetical "undistorted" image - i.e. the output image. A camera matrix has 4 important fields 2 focal lengths (for x and y), and 2 shifts - the coordinates of the "principal point". First two allow for scaling, the latter can shift the viewpoint. I also tried to rectify the image in one go, by multiplying the inNewCameraMatrix by inverse of rotation matrix from the extrinsic parameters of camera calibration (to look exactly along the z-axis).Hardily
E
3

In the case of monocular camera newCameraMatrix is usually equal to cameraMatrix , or it can be computed by GetOptimalNewCameraMatrix for a better control over scaling.

Check out http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html#cv-getoptimalnewcameramatrix

Edifice answered 2/7, 2012 at 18:31 Comment(1)
Any chance you can post the relevant code? The link is dead.Valval

© 2022 - 2024 — McMap. All rights reserved.