python – OPENCV:Calibratecamera 2重投影错误和自定义计算错误

前端之家收集整理的这篇文章主要介绍了python – OPENCV:Calibratecamera 2重投影错误和自定义计算错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个python脚本,使用calibratecamera2方法从棋盘的几个视图校准相机.校准成功后,我会检查所有原始点并做一些绘图并再次计算重新投影误差.令我惊讶的是,opencv和我计算的重投影错误有点不同.我发现它很奇怪.我是以错误的方式计算它的吗?

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),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],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

平均重投影错误:0.438696960449

最佳答案
我的计算错误/不同.我正在使用这种公式:

但opencv使用这个:

所以,如果有人感兴趣,代码现在看起来像:

#Compute mean of reprojection error
tot_error=0
total_points=0
for i in xrange(len(obj_points)):
    reprojected_points,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

平均重投影错误:0.571030718956

猜你在找的Python相关文章