【问题标题】:OPENCV: Calibratecamera 2 reprojection error and custom computed one not agreeOPENCV:Calibratecamera 2 重投影误差和自定义计算的不同意
【发布时间】:2014-07-09 23:19:22
【问题描述】:

我有一个 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), 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

【问题讨论】:

    标签: python opencv camera calibration


    【解决方案1】:

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

    但是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

    【讨论】:

    • 您的代码是正确的,但该等式与代码不匹配。您的代码计算单个图像的重投影误差,并且分子中应该只有一个 d(x, x')。分子中两个位移误差之和的方程是用于最小化单应性的两个图像中对应点之间的重投影误差的方程。
    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    相关资源
    最近更新 更多