Ask Your Question

What does the getOptimalNewCameraMatrix function does?

asked 2016-08-31 02:42:40 -0500

Hilman gravatar image

updated 2016-08-31 03:06:52 -0500

berak gravatar image

For example, in this tutorial, I have some problems in understanding the cv2.getOptimalNewCameraMatrix. Already read the documentation and made some search, but I still can't understand it. I don't get the meaning of the return of this function:

Returns the new camera matrix based on the free scaling parameter

What does "free scaling parameter" means?

I hope someone can give explanation and maybe some examples on this. Thanks.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2016-12-22 16:15:38 -0500

mannyglover gravatar image

updated 2018-11-15 16:49:17 -0500

Undistorted image lots of black

Consider the image above. It has been undistorted. Lines that are straight in 3D space are now straight in the 2D projection (the 2D image). Radial distortion has been removed. But what's up with the "four pointed star" shape? This is because in order to correct for radial distortion, pixels that are further away from the center of distortion must get pushed more than pixels closer to the center of distortion. See the picture below:

image description

The red dots represent pixel locations before undistorting: they follow a regular grid. But the radial distortion model says that as one moves away from center of distortion, the distortion gets worse. It is called a radial distortion model because this is a function of the size of the radius of a circle centered around the center of distortion. The heads of the blue vectors represent where the red pixels will get undistorted to. Since the original image is a rectangle, the points toward the corners have the highest radius, and they must get pushed out more. But if you want to see every pixel from the original image, this means you will have the black "hills" on the sides of the undistorted image. If you don't want to see these black hills, set alpha to 0. If you do want to see these black hills, set alpha to 1. If you want to see the black hills, but you want them to be smaller, set alpha to 0.5. You get the picture.

edit flag offensive delete link more


Parallel lines in 3D space do not have to be parallel in the 2D projection space. Instead,

Straight Lines Have to Be Straight

see this paper.

Eduardo gravatar imageEduardo ( 2016-12-24 12:52:37 -0500 )edit

answered 2016-08-31 04:37:36 -0500

Ice_T02 gravatar image

If i understand it correctly it refines your camera calibration parameters based on the input of alpha (0-1). I don't know if you had a look at this.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-08-31 02:42:40 -0500

Seen: 3,840 times

Last updated: Nov 15 '18