python cv2 stereoCalibrate [closed]

asked 2018-10-25 05:46:03 -0500

wildwallaby gravatar image

When trying to use the python function cv2.stereCalibrate() I am receiving an "Assertion error -215".
I am able to get a successful monocular calibration with cv2.cameraCalibrate().

The traceback is as follows:
cv2.error: OpenCV(3.4.3) /Users/travis/build/skvark/opencv-python/opencv/modules/calib3d/src/calibration.cpp:3136: error: (-215:Assertion failed) nimages > 0 && nimages == (int) && (!imgPtMat2 || nimages == (int) in function 'collectCalibrationData'

Has anyone found a workaround to this ?


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-13 13:46:10.857162


can you show the relevant piece of code ?

the error mainly says, that it did not find enough chessboard corners in some of the images

berak gravatar imageberak ( 2018-10-25 06:47:25 -0500 )edit

Thanks for the rapid response. The lengths of the objpoints, imgpoints_l and imgpoints_r are 52, 39, 23 respetively. I thought that these would indicate that enough corners have been found. Perhaps I am missing something else. I am opting to calculate the camera and distortion matrices just with cv2.stereoCalibrate(). Below is a code snippet.
M1, M2 = np.zeros((3,3)), np.zeros((3,3))
d1, d2 = np.zeros((3,1)), np.zeros((3,1))

stereocalib_criteria = (cv2.TERM_CRITERIA_MAX_ITER +
cv2.TERM_CRITERIA_EPS, 30, 1e-5)

ret, M1, d1, M2, d2, R, T, E, F = cv2.stereoCalibrate(
self.objpoints, self.imgpoints_l,
self.imgpoints_r, M1, d1, M2,
d2, dims,
criteria=stereocalib_criteria, flags=flags)
Thanks for your help.

wildwallaby gravatar imagewildwallaby ( 2018-10-25 07:45:15 -0500 )edit

look at the shapes for self.objpoints, self.imgpoints_l, self.imgpoints_r. they should have all the same length.

you should have rejected image pairs earlier on, which do not have the full number of expected chessboard corners.

again, ALL chessboard corners need to be detected.

berak gravatar imageberak ( 2018-10-25 07:59:14 -0500 )edit