Ask Your Question
0

cv::CalibrateCamera vs. cvCalibateCamera2 difference ?

asked 2014-05-16 03:21:05 -0600

Thibault gravatar image

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

edit retag flag offensive close merge delete

Comments

1

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 ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-16 03:41:16 -0600 )edit

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.

Thibault gravatar imageThibault ( 2014-05-16 05:36:03 -0600 )edit

Hmmm what openCV version you using?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-16 05:43:32 -0600 )edit

I'm using 2.4.2 in both case.

Thibault gravatar imageThibault ( 2014-05-16 06:33:57 -0600 )edit

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!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-16 06:38:11 -0600 )edit
1

Ok i'll give that a try and come back.

Thibault gravatar imageThibault ( 2014-05-16 06:47:08 -0600 )edit

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 ...

Thibault gravatar imageThibault ( 2014-05-16 07:34:20 -0600 )edit

It might be a good idea to post a bug at the dev forum linking it to this discussion.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-16 07:52:13 -0600 )edit
1

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

Thibault gravatar imageThibault ( 2014-05-16 08:16:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-05-19 00:10:59 -0600

Thibault gravatar image

I'm sorry after all it was my mistake. When I tried to make a sample code to report the bug I found out the problem came from my application. It was the size argument in cv::CalibrateCamera that sometimes contained wrong values leading to calibration error.

Thanks anyways it helped me figure it out !

edit flag offensive delete link more

Comments

Do click on your answer as the solution. your karma should be enough now.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-19 01:56:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-05-16 03:21:05 -0600

Seen: 5,488 times

Last updated: May 19 '14