python的cv2.calibrateCamera的输入参数 [英] input arguments of python's cv2.calibrateCamera
问题描述
当我尝试使用cv2.calibrateCamera校准相机时出现以下错误:
I get the following error when I try to calibrate camera using 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)的向量作为输入:
I initially had nx3 and nx2 array for pts3d and pts2d. I then tried to reshape pts3d and pts2d in the following form as the function takes vectors of vector point3d (and correspondingly pts2d) as input:
[1 x n x 3]和[1 x n x 2]
[1 x n x 3] and [1 x n x 2]
[k x n'x 3]和[k x n'x 3],其中k是某个随机值
[k x n' x 3] and [k x n' x 3], where k is some random value
[1 x n x 1 x 3]和[1 x n x 1 x 2]
[1 x n x 1 x 3] and [1 x n x 1 x 2]
没有任何效果,并且始终会给出相同的错误.
nothing works and it always gives the same error.
我看到了提供的cameraclibration的代码示例代码,该代码示例运行良好,其输入为[k x n x 3].我真的不知道我的实现有什么问题.以下是我的精确代码:
I saw the code sample code of cameraclibration provided which runs fine, and their input is of [k x n x 3]. I really don't know what is wrong with my implementation. Following is my code to be precise:
#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)
该错误在函数调用时发生.很高兴知道这里可能出什么问题.
the error happens at the time of the function call. It would be nice to know what can be wrong here.
推荐答案
我遇到了同样的问题,并在以下主题找到了答案: OpenCV 2.3摄像机校准
I had the same problem and found the answer for it at this topic: 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中的dev分支)也适用.
It was written for OpenCV 2.3, but it works for me even with OpenCV 3.0 (dev branch in git) with Python 3.3.5 (64 bit).
这篇关于python的cv2.calibrateCamera的输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!