Ask Your Question

Camera calibration and aspect ratio

asked 2016-07-01 09:13:22 -0500

logidelic gravatar image

updated 2016-07-01 14:25:08 -0500


I am calibrating a wide-angle IP Cam. Here as an example of the image after calling remap() with the calibration data:

image description

Lines are straight. Good. However, notice that the checkboard squares are tall. They are rectangles instead of squares. Bad. Should the calibration process have made this good? How do I correct for this?

When performing the calibration (for the example posted), I am not using the CALIB_FIX_ASPECT_RATIO flag. However, I have tried it with the flag (using it correctly as per the sample) and end up with the same problem. I understand that this flag indicates that there is a known pixel-size-ratio, but if I don't provide the flag, I assumed that this would have been calculated, right?

Edit: I think think this is definitely related to the camera not having square pixels (at least the resolution I was trying here), but I'm still not clear as to whether OpenCV's calibration should be able to correct for this automatically or not...?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-07-22 14:31:33 -0500

dandur gravatar image

updated 2016-07-23 01:01:46 -0500

The correct way is not using CALIB_FIX_ASPECT_RATIO flag or set this flag and apply aspect ratio in initial camera matrix. It is strange that first approach doesn't work in your case. Can you show your calibration code?

Also, for better accuracy I would recomend you calibrate camera with native resolution and then rescale camera matrix (distortion coefficents remain the same). For recovering scale (and maybe crop) parameters take some shots of calibration rig with native and working resolution. Then find transformation between corners coordinates on different resolution. The transformation will have a form:

new_x = (x - crop_x) * scale_x
new_y = (y - crop_y) * scale_y

Also note that crop_x and crop_y should be integer values and scale_x and scale_y are probably rational values. Finaly rescale camera matrix parameters:

new_fx = fx * scale_x
new_fy = fy * scale_y
new_cx = (cx - crop_x) * scale_x
new_cy = (cy - crop_y) * scale_y

UPD I just thought that your problem may be related to the wrong parameter newCameraMatrix in initUndistortRectifyMap. Use getOptimalNewCameraMatrix for this parameter.

edit flag offensive delete link more

Question Tools



Asked: 2016-07-01 09:13:22 -0500

Seen: 1,794 times

Last updated: Jul 23 '16