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):
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:
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):
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.
you MUST NOT use the deprecated c-api.
have a look here, please
Ahem this is funny...this is some legacy code I can't easily change - so isn't it allowed to ask such questions?
you can't keep your legacy code forever. (and it seems, you're writing even more of this)
@berak: it is not my personal decision to keep the code or to drop it, it has to do with certifications that need to be done on machines - and in industry applications stay alive for more than ten years typically. so when today somebody changes an API in an fancy, fantastic, extremely useful way, this can be applied to NEW products only, the existing ones need to stay with the old code for several years