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
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.
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.
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.
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.
I was computing it wrong/differently. I was using this kind of formula:
But opencv uses this one:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With