【问题标题】:input arguments of python's cv2.calibrateCamerapython cv2.calibrateCamera 的输入参数
【发布时间】:2015-06-04 22:45:00
【问题描述】:

当我尝试使用 cv2.calibrateCamera 校准相机时出现以下错误:

rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(pts3d, pts2d, self.imgsize, None, None)
cv2.error: /home/sarkar/opencv/opencv/modules/calib3d/src/calibration.cpp:2976: error: (-210) objectPoints should contain vector of vectors of points of type Point3f in function collectCalibrationData

我最初有用于 pts3d 和 pts2d 的 nx3 和 nx2 数组。然后我尝试以以下形式重塑 pts3d 和 pts2d,因为该函数将向量 point3d(以及相应的 pts2d)的向量作为输入:

[1 x n x 3] 和 [1 x n x 2]

[k x n' x 3] 和 [k x n' x 3],其中 k 是某个随机值

[1 x n x 1 x 3] 和 [1 x n x 1 x 2]

没有任何效果,它总是给出同样的错误。

我看到提供的cameraclibration的代码示例代码运行良好,它们的输入是[k x n x 3]。我真的不知道我的实施有什么问题。准确地说,以下是我的代码:

   #data contains [n x 5] dim array which is the hstacked arrays of pts3d and pts2d correspondences I obtained elsewhere. 
    pts3d = data[:, 0:3] #first 3 column 
    pts2d = data[:, 3:5] #next 2 column.. I checked the values are coming correctly 
    pts3d = pts3d.reshape(1,-1, 3) #Here, I have experimented by resizing with different values. 
    pts2d = pts2d.reshape(1,-1, 2)

    rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(pts3d, pts2d, self.imgsize, None, None)    

错误发生在函数调用时。很高兴知道这里可能出了什么问题。

【问题讨论】:

    标签: opencv camera-calibration opencv3.0


    【解决方案1】:

    我遇到了同样的问题,并在这个主题中找到了答案: OpenCV 2.3 camera calibration

    主要步骤是:

    pts3d = pts3d.astype('float32')
    pts2d = pts2d.astype('float32')
    
    # This can be omitted and can be substituted with None below.
    camera_matrix = cv2.initCameraMatrix2D([pts3d],[pts2d]), self.imgsize)  
    
    cv2.calibrateCamera([pts3d], [pts2d], self.imgsize, camera_matrix, None, 
                        flags=cv2.CALIB_USE_INTRINSIC_GUESS)
    

    它是为 OpenCV 2.3 编写的,但即使使用 Python 3.3.5(64 位)的 OpenCV 3.0(git 中的开发分支)也适用于我。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    • 感谢您的评论。我添加了主要步骤。
    【解决方案2】:

    我正在使用 OpenCV 3.4,发现 pts3d(形状 1 * n * 3)和 pts2d(形状 1 * n * 2)对我有用。只需记住将类型(我的默认类型是 float64)更改为 float32,正如 Csega 所指出的。

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 2021-10-24
      • 2015-06-20
      • 2018-10-27
      • 1970-01-01
      • 2017-03-26
      相关资源
      最近更新 更多