gpt4 book ai didi

python - 为什么 OpenCV 认为我使用的是非平面校准装置?

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:32 25 4
gpt4 key购买 nike

我正在玩模拟相机装备,试图了解 OpenCV 的 calib3d 模块的工作和执行方式。

我在 3D 空间中创建了一组人工对象点,对应于 z=50 处的九个平面网格:

obj_pts = np.zeros((9, 3), dtype='float32')
obj_pts[0] = np.array([40, 40, 50], dtype='float32')
obj_pts[1] = np.array([50, 40, 50], dtype='float32')
obj_pts[2] = np.array([60, 40, 50], dtype='float32')
obj_pts[3] = np.array([40, 50, 50], dtype='float32')
obj_pts[4] = np.array([50, 50, 50], dtype='float32')
obj_pts[5] = np.array([60, 50, 50], dtype='float32')
obj_pts[6] = np.array([40, 60, 50], dtype='float32')
obj_pts[7] = np.array([50, 60, 50], dtype='float32')
obj_pts[8] = np.array([60, 60, 50], dtype='float32')

然后我在创建人造相机后使用 cv2.projectPoints() 对其进行了成像:

rvec = (0, 0, 0)  # rotation relative to the frame
tvec = (0, 0, 0) # translation relative to the frame
distCoeffs = (0, 0, 0, 0)
cameraMatrix = np.zeros((3, 3))
focalLength = 50
cx = 0
cy = 0
setupCameraMatrix(cameraMatrix, focalLength, cx, cy) # my own routine

img_pts, jacobian = cv2.projectPoints(obj_pts, rvec, tvec, cameraMatrix, distCoeffs)

使用上面的参数投影到图像平面上,图像点看起来像这样(红点只是表示左下角的方向):

Plot of the artificial image points projected into image plane

最后我尝试检索原始相机校准:

obj_pts_list = [obj_pts]
img_pts_list = [img_pts]
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_pts_list, img_pts_list, (200, 200), None, None)

但是这最后一步给出了这个错误:

OpenCV Error: Bad argument (For non-planar calibration rigs the initial intrinsic matrix must be specified) in cvCalibrateCamera2, file /tmp/opencv20150527-4924-hjrvz/opencv-2.4.11/modules/calib3d/src/calibration.cpp, line 1592

我的问题不是关于如何修复这个错误本身 - 而是为什么它首先被抛出?当所有对象点位于同一平面时,为什么此设置构成非平面装备?我误解了吗?

最佳答案

OpenCV 期望 z = 0,因为它是平面校准目标的情况。

查看代码,OpenCV 按如下方式检查此值:

Scalar mean, sdv;
meanStdDev(matM, mean, sdv);
if( fabs(mean[2]) > 1e-5 || fabs(sdv[2]) > 1e-5 )
CV_Error( CV_StsBadArg,
"For non-planar calibration rigs the initial intrinsic matrix must be specified" );

这意味着将 z 设置为 0 以外的值会触发错误。除非使用非平面校准目标,否则必须使用 z = 0

关于python - 为什么 OpenCV 认为我使用的是非平面校准装置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31367255/

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