【问题标题】:Why does OpenCV think I am using a non-planar calibration rig?为什么 OpenCV 认为我在使用非平面校准装置?
【发布时间】:2015-07-12 11:24:39
【问题描述】:

我正在玩一个模拟摄像机装置,试图了解 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)

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

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

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

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

【问题讨论】:

    标签: python opencv computer-vision camera-calibration


    【解决方案1】:

    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,除非使用非平面校准目标。

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 2021-12-30
      • 2013-02-24
      • 1970-01-01
      • 2016-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      相关资源
      最近更新 更多