输入python&c; cv2.calibrateCamera的参数

时间:2015-03-31 14:36:45

标签: opencv camera-calibration opencv3.0

当我尝试使用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)    

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

2 个答案:

答案 0 :(得分:5)

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

主要步骤是:

DoIt(this.token)

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

答案 1 :(得分:0)

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

相关问题