Ask Your Question
0

python ret value vastly different from reprojection error

asked 2019-08-14 04:12:53 -0500

dnns gravatar image

In this question, I am referring to the documentation example given here: https://docs.opencv.org/4.1.0/dc/dbb/...

To give a short summary: It's an example on how to calibrate a camera using a chessboard-pattern. In the example the author calibrates the camera like this:

ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)

It is stated in the documentation, that the ret-value is supposed to be the overall RMS of the reprojection error: (Check: https://docs.opencv.org/4.1.0/d9/d0c/...)

However, at the end of the script, the author calculates the reprojection error like this:

mean_error = 0
for i in xrange(len(objpoints)):
    imgpoints2, _ = cv.projectPoints(objpoints[i], rvecs[i], tvecs[i], mtx, dist)
    error = cv.norm(imgpoints[i], imgpoints2, cv.NORM_L2)/len(imgpoints2)
    mean_error += error
print( "self-calculated error: {}".format(mean_error/len(objpoints)) )
print( "ret-value: {}".format(ret))

So this does - to my understanding - calculate the average normed reprojection-error per point per image. However, this is vastly different from the ret-value, that is given back to the user by calibrateCamera. Running the code and comparing the results leads to the results:

self-calculated error: 0.02363595176460404
ret-value: 0.15511421684649151

These are an order of maginute different and I think that should not be the case, ...right (?!) And the more important question: It is often stated, that the most important value to define "a good calibration" is a reprojection error < 1 and close to zero. Which reprojection error should be used for that?

I really hope someone can answer this question as it has been bugging me for a week now.

Cheers,

Dennis

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2019-08-15 04:38:56 -0500

dnns gravatar image

I found this on StackOverflow, which answers the question. The sum must be calculated inside the root. However the formula the answer provides is slightly incorrect, as the formula should be: \sqrt(\sum(diff(x-x0)²/n)https://stackoverflow.com/questions/2...

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-08-14 04:12:53 -0500

Seen: 15 times

Last updated: Aug 15