Vladislav D
Vladislav D

Reputation: 87

cv2.stereoCalibrate throws assertion failed

I'm using opencv-contrib-python (4.5.4.60) to calibrate stereovision emulated by 2 pictures taken with one camera (for now I only have one of them) like there are two cameras for stereo depth estimation in future. I find intrinsic parameters of camera from several photos and trying to pass ChAruCo markers points from two photos into stereoCalibrate, but get assertion failed:

ret, M1, d1, M2, d2, R, T, E, F = cv2.stereoCalibrate(objpoints_L, imgpoints_L, imgpoints_R, camera_matrix, distortion_coefficients0, camera_matrix, distortion_coefficients0,img_r1.shape[:2], F = F)
cv2.error: OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\calib3d\src\calibration.cpp:1088: error: (-215:Assertion failed) (count >= 4) || (count == 3 && useExtrinsicGuess) in function 'cvFindExtrinsicCameraParams2'

I have checked input type of object points and image points with cv2.utils.dumpInputArray()

InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=40 dims(-1)=2 size(-1)=1x40 type(-1)=CV_32FC3
InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=40 dims(-1)=2 size(-1)=1x40 type(-1)=CV_32FC2
InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=40 dims(-1)=2 size(-1)=1x40 type(-1)=CV_32FC2

sorted them so I pass only matching on both photos, but still get assertion failed and can't figure out what I'm doing wrong.

Upvotes: 2

Views: 388

Answers (1)

Vladislav D
Vladislav D

Reputation: 87

The problem was that ChAruCo markers are returned as array of objects with single point (n, 1, 2) by cv2.aruco.detectMarkers. Functions accept this points format (for example cv2.solvePnP or cv2.findFundamentalMat) but if you try to pass them into cv2.stereoCalibrate, which checks for every object to have more then 3 points but get n objects with single point instead, you would get assertion failed. To use this points you have to reshape array to single object with all ChAruCo points (1,n,2). Do the same reshape to (1, n, 3) to object points obtained by cv2.aruco.getBoardObjectAndImagePoints.

Upvotes: 1

Related Questions