# Camera calibration and aspect ratio

Hello!

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

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 close merge delete

Sort by » oldest newest most voted

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.

more

Official site

GitHub

Wiki

Documentation