Ask Your Question

Revision history [back]

cvCalibrateCamera2 does not fully compensate spatial distortion

I have a problem with the OpenCV function cvCalibrateCamera2. I'm using the checkerboard (with squares on it) for calibration, due to the camera position they are distorted this way (original image comes without the dots and the crosshairs, this is only what is displayed to the user):

image description

Now when I perform calibration using these parameters...

// set aspect ratio to fx and fy
CV_MAT_ELEM(*intrinsic_matrix,float,0,0)=1.0; // fx
CV_MAT_ELEM(*intrinsic_matrix,float,1,1)=(1.0*calib_data->height)/calib_data->width; // fy
cvCalibrateCamera2(object_points,image_points,point_counts,cvGetSize(gray_image),
                 intrinsic_matrix, distortion_coeffs,
                 NULL,NULL,
                 CV_CALIB_FIX_ASPECT_RATIO);

...the spatial distortion is somehow compensated, but this results in rectangles but not in squares:

image description

Means the depth-information is OK but the image would need to be stretched some more in order to come back to real squares. When I remove flag CV_CALIB_FIX_ASPECT_RATIO and replace it by 0, the image is a bit more stretched into the right direction but still far away from being correct (more than this it is overcompensated):

image description

So...any idea what needs to be changed in order to get a suitable correction which also restores the correct image aspect ratio?

Just to note: the input image is not taken from a real world camera but from a precalculated picture, so it should be perfectly suitable for this kind of correction.