当我尝试使用 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 数组。然后我尝试按以下形式 reshape 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 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 编写的,但即使是 OpenCV 3.0(git 中的开发分支)和 Python 3.3.5(64 位),它也适用于我。
关于opencv - python cv2.calibrateCamera 的输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371273/