input arguments of python's cv2.calibrateCamera

廉价感情. 提交于 2019-12-18 13:31:52

问题


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

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] and [1 x n x 2]

[k x n' x 3] and [k x n' x 3], where k is some random value

[1 x n x 1 x 3] and [1 x n x 1 x 2]

nothing works and it always gives the same error.

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.


回答1:


I had the same problem and found the answer for it at this topic: OpenCV 2.3 camera calibration

The main steps are:

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)

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).




回答2:


I'm using OpenCV 3.4 and found that pts3d (shape 1 * n * 3) and pts2d (shape 1 * n * 2) works for me. Just remember to change type (my default type is float64) to float32, as Csega noted.



来源:https://stackoverflow.com/questions/29371273/input-arguments-of-pythons-cv2-calibratecamera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!