OPENCV:Calibratecamera 2 重投影错误和自定义计算的不同意

OPENCV: Calibratecamera 2 reprojection error and custom computed one not agree(OPENCV:Calibratecamera 2 重投影错误和自定义计算的不同意)
本文介绍了OPENCV:Calibratecamera 2 重投影错误和自定义计算的不同意的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

推荐答案

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

I was computing it wrong/differently. I was using this kind of formula:

但是opencv用的是这个:

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

最终重投影错误opencv:0.571030279037

Final reprojection error opencv: 0.571030279037

平均重投影误差:0.571030718956

Mean reprojection error:0.571030718956

这篇关于OPENCV:Calibratecamera 2 重投影错误和自定义计算的不同意的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

patching a class yields quot;AttributeError: Mock object has no attributequot; when accessing instance attributes(修补类会产生“AttributeError:Mock object has no attribute;访问实例属性时)
How to mock lt;ModelClassgt;.query.filter_by() in Flask-SqlAlchemy(如何在 Flask-SqlAlchemy 中模拟 lt;ModelClassgt;.query.filter_by())
FTPLIB error socket.gaierror: [Errno 8] nodename nor servname provided, or not known(FTPLIB 错误 socket.gaierror: [Errno 8] nodename nor servname provided, or not known)
Weird numpy.sum behavior when adding zeros(添加零时奇怪的 numpy.sum 行为)
Why does the #39;int#39; object is not callable error occur when using the sum() function?(为什么在使用 sum() 函数时会出现 int object is not callable 错误?)
How to sum in pandas by unique index in several columns?(如何通过几列中的唯一索引对 pandas 求和?)