cv::CalibrateCamera vs. cvCalibateCamera2 difference ?
Hi,
I am using two different codes for camera calibration (one with the old C interface and one with the C++ interface) I want to unify this using only C++ interface but when I run the functions cv::calibrateCamera and cvCalibrateCamera2 on the exact same data I get different results and the C results are much better.
Here is the core function that I tested :
vector<vector<Point3f>> modele_points;
vector<vector<Point2f>> image_points;
//I skip the code to fill the vectors
double rms_error = calibrateCamera(model_points, image_points,size, intrinsic, disto, rotations, translations,flags);//flags = 0
and :
CvMat* cam_image_points = cvCreateMat(n_boards*cam_board_n,2, CV_32FC1);
CvMat* cam_object_points = cvCreateMat(n_boards*cam_board_n,3, CV_32FC1);
CvMat* cam_point_counts = cvCreateMat(n_boards, 1, CV_32SC1);
CvMat* cam_rotation_vectors = cvCreateMat(n_boards, 3, CV_32FC1);
CvMat* cam_translation_vectors = cvCreateMat(n_boards, 3, CV_32FC1);
CvMat* camera_matrix = cvCreateMat(3,3,CV_32F);
CvMat *dist_coeffs = cvCreateMat(5,1,CV_32FC1);
//Filling the matrices
double rms_error = cvCalibrateCamera2(cam_object_points,cam_image_points, cam_point_counts, image_size, camera_matrix, dist_coeffs,cam_rotation_vectors,cam_translation_vectors);
I wrote the content of model_points and cam_object_points in a file, they are exactly the same. And image_points also contains the same values as cam_image_points. Those values are obtained using chessboard detection and subpixel corner refinement respectively with c++ and c interface. But I get different results cvCalibrateCamera2 returns a rms error of 0.1 on my data and calibrateCamera returns an error of 0.8 with a different camera matrix whose values are not completely out of the expected range but are not as good as those of cvCalibrateCamera2 by far.
Is there a big difference between the two versions that could explain the different results ? Could there be a problem in the way i use these functions.
I can provide more information on request (values or whatever) if needed.
Thanks in advance.
Thibault
First of all all cv... functions are old C-API. The ones without are the newer C++ API and are the only one who give a guaranteed succes or correct output. They will drop the unsupported and deprecated C API in one of the following releases. So I wouldn't trust the C output myself ...
Thanks for your comment, that's the reason I want to get rid of all the old C-API functions. The problem is I get wrong results with the C++-API on the exact same data whereas C-API provides still the good answer.
Hmmm what openCV version you using?
I'm using 2.4.2 in both case.
Ok, first of all, download 2.4.9 (latest stable release) or even build openCV from even more latest 2.4 branch! Good chance your bug is already fixed since then!
Ok i'll give that a try and come back.
Ok i tried with 2.4.9, it doesn't change anything I still have the same results with better results calling the C-API ...
It might be a good idea to post a bug at the dev forum linking it to this discussion.
Ok i'll do that. I'll triple check my data to make sure I didn't miss anything but I have tested on several datasets and I sometimes have exactly the same values and soemtimes they are different with better results for the C-API always