输入python的cv2.calibrateCamera参数

kri*_*s89 5 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
Run Code Online (Sandbox Code Playgroud)

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

[1 xnx 3]和[1 xnx 2]

[kxn'x 3]和[kxn'x 3],其中k是一些随机值

[1 xnx 1 x 3]和[1 xnx 1 x 2]

没有任何作用,它总是给出相同的错误.

我看到提供了cameraclibration的代码示例代码,运行正常,输入为[kxnx 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)    
Run Code Online (Sandbox Code Playgroud)

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

小智 6

我有同样的问题,并在这个主题找到答案: OpenCV 2.3相机校准

主要步骤是:

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)
Run Code Online (Sandbox Code Playgroud)

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