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

给你一囗甜甜゛ 提交于 2019-12-18 13:32:12

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/23781089/opencv-calibratecamera-2-reprojection-error-and-custom-computed-one-not-agree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!