gpt4 book ai didi

python - OPENCV:Calibratecamera 2 重投影错误和自定义计算不一致

转载 作者:太空狗 更新时间:2023-10-30 01:15:09 26 4
gpt4 key购买 nike

我有一个 python 脚本,它使用 calibratecamera2 方法从棋盘的几个 View 校准相机。成功校准后,我追踪所有原始点并绘制一些图并再次计算重新投影误差。令我惊讶的是,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), 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

平均重投影误差:0.438696960449

最佳答案

我计算错误/不同。我使用的是这种公式:

formula

但是opencv用的是这个:

fomrula_opencv

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

#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

平均重投影误差:0.571030718956

关于python - OPENCV:Calibratecamera 2 重投影错误和自定义计算不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23781089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com