Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OPENCV: Calibratecamera 2 reprojection error and custom computed one not agree

I have a python script that uses the calibratecamera2 method to calibrate a camera from a few views of a checker board. After a successful calibration I go after all original points and do some plots and compute again the re-projection error. My surprise is that the reprojection error computed by opencv and mine are a bit different. I found it strange. Am I computing it in a wrong way?

obj_points = []# 3d point in real world space. List of arrays
img_points = []# 2d points in image plane. List of arrays

...

ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(obj_points, img_points, (w, h), camera_matrix, dist_coeffs, rvecs, tvecs, calib_flags +cv2.CALIB_USE_INTRINSIC_GUESS, criteria)
print "Final reprojection error opencv: ", ret   #Compute mean of reprojection error
tot_mean_error=0
mean_error_image = 0
for i in xrange(len(obj_points)):
    reprojected_points, _ = cv2.projectPoints(obj_points[i], rvecs[i], tvecs[i], camera_matrix, dist_coeffs)
    reprojected_points=reprojected_points.reshape(-1,2)
    mean_error_image=np.sum(np.sum(np.abs(img_points[i]-reprojected_points)**2,axis=-1)**(1./2))/np.alen(reprojected_points)
    tot_mean_error +=mean_error_image

mean_error=tot_mean_error/len(obj_points)
print "Mean reprojection error: ", mean_error

Final reprojection error opencv: 0.571030279037

Mean reprojection error: 0.438696960449

like image 251
Josep Bosch Avatar asked May 21 '14 10:05

Josep Bosch


People also ask

What causes reprojection error?

This error depends on the quality of the camera calibration (position and orientation), as well as on the quality of the marked point on the images (position and zoom level at which the point is marked). The distance between the marked and the reprojected point on one image is the reprojection error.

How is reprojection error calculated?

It is important to understand that reprojection error is not a final answer. Overall_error^2 = reprojection_error^2 + estimation_error^2. The latter is the distance between estimation reprojected and true point on the model.

What is reprojection error in camera calibration?

A reprojection error is the distance between a pattern keypoint detected in a calibration image, and a corresponding world point projected into the same image. The showReprojectionErrors function provides a useful visualization of the average reprojection error in each calibration image.

What is a good reprojection error?

With a good test setup, projection error should be low - approximately on the same order as the calibration score, or typically in the 0.02-0.05 range. Slightly higher errors are generally not an indication of a problem although errors of approximately 0.1 or above may indicate issues.


1 Answers

I was computing it wrong/differently. I was using this kind of formula:

formula

But opencv uses this one:

fomrula_opencv

So, if anyone is interested the code looks now like:

#Compute mean of reprojection error
tot_error=0
total_points=0
for i in xrange(len(obj_points)):
    reprojected_points, _ = cv2.projectPoints(obj_points[i], rvecs[i], tvecs[i], camera_matrix, dist_coeffs)
    reprojected_points=reprojected_points.reshape(-1,2)
    tot_error+=np.sum(np.abs(img_points[i]-reprojected_points)**2)
    total_points+=len(obj_points[i])

mean_error=np.sqrt(tot_error/total_points)
print "Mean reprojection error: ", mean_error

Final reprojection error opencv: 0.571030279037

Mean reprojection error:0.571030718956

like image 97
Josep Bosch Avatar answered Nov 25 '22 23:11

Josep Bosch