Camera calibration is very slow for large number of images

I’m calibrating my camera with a large number of images and it takes forever to calibrate it. Here is a plot of calibrateCamera execution time. It grows very quickly. The code is in C++, in release mode, with OpenMP enabled and compiler optimizations. Still, it looks like only 1 core is working.

On the same machine, the same images were used in Matlab. The execution time of an equivalent function estimateCameraParameters is nearly flat and it varies from 0.06 seconds for 20 images to 2.2 seconds for 150 images. For OpenCV these times are: 1 and 756 seconds, respectively. That is a huge difference.

Any idea why OpenCV implementation is so slow?

Note: I’m timing only the calibration functions, not image loading or chessboard detection!

1 Like

You say it is an equivalent function in Matlab that seems to run faster. How do you know it is equivalent? The input and output might be the same, but the implementation / method could be different. Do they give the same results?

Also you say the Matlab function is nearly flat (which I take to mean that the time it takes is linear in the number of input images), but I think it’s closer to quadratic, it’s just that the amount of time is small, so it seems acceptable.

I’m not sure why the OpenCV funciton is so much slower than the Matlab function, but it could be that the Matlab function is more efficiently implemented, or it could be that the OpenCV function produces better results at the cost of higher complexity.

Is there a reason you want to calibrate with such a large number of input images? I did a good amount of testing (both with synthetic data and real world data) and, at least for my purposes / application, I didn’t see any benefit beyond 15 images (and actually I think it was less than that, but I used 15 because why not.)

I have meet a case in which photo resolution is very big ,4096*4096. it is very slow in opencv calib.i solve it by resize it before get corners,that is get the pic smaller;after get corners,I resize the corners to the true size of pic.In this way, the result is still good in rms 0.01 errors.

I am sorry ,but i really cannot get acess to matlab for its is not a good ideas to get more than 15 or 20 photos to calib i think.

may it wiil help you.