問題描述
我有一個 python 腳本,它使用 calibratecamera2 方法從棋盤的幾個視圖中校準(zhǔn)相機(jī).成功校準(zhǔn)后,我會追蹤所有原始點(diǎn)并繪制一些圖并再次計(jì)算重投影誤差.令我驚訝的是,opencv 計(jì)算的重投影誤差和我的有點(diǎn)不同.我覺得很奇怪.我是否以錯誤的方式計(jì)算它?
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
最終重投影錯誤opencv:0.571030279037
Final reprojection error opencv: 0.571030279037
平均重投影誤差:0.438696960449
Mean reprojection error: 0.438696960449
推薦答案
我計(jì)算錯誤/不同.我正在使用這種公式:
I was computing it wrong/differently. I was using this kind of formula:
但是opencv用的是這個:
But opencv uses this one:
所以,如果有人感興趣,代碼現(xiàn)在看起來像:
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
最終重投影錯誤opencv:0.571030279037
Final reprojection error opencv: 0.571030279037
平均重投影誤差:0.571030718956
Mean reprojection error:0.571030718956
這篇關(guān)于OPENCV:Calibratecamera 2 重投影錯誤和自定義計(jì)算的不同意的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!