Search code examples
pythonopencvcomputer-visionstereo-3d

Python - OpenCV stereoCalibrate() too manu values to unpack


I am using OpenCV for stereo calibration. I have already performed calibration of individual cameras. For the following code snippet:

ret, rot, trans, ess, fund = cv2.stereoCalibrate(objectPoints=objpoints,
                                                 imagePoints1=imgpoints1,
                                                 imagePoints2=imgpoints2,
                                                 cameraMatrix1=mtx1,
                                                 distCoeffs1=dist1,
                                                 cameraMatrix2=mtx2,
                                                 distCoeffs2=dist2,
                                                 imageSize=gray1.shape[::-1],
                                                 flags=cv2.CALIB_FIX_INTRINSIC)

I get the error:

Traceback (most recent call last):
   File "stereoCalibration.py", line 94, in <module>
  flags=cv2.CALIB_FIX_INTRINSIC)
ValueError: too many values to unpack (expected 5)

But I already have five variables on the left-hand-side. According to this documentation, the function cv2.stereoCalibrate() should return 5 values when flags=cv2.CALIB_FIX_INTRINSIC.

Python: cv2.stereoCalibrate(objectPoints, imagePoints1, imagePoints2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize[, R[, T[, E[, F[, flags[, criteria]]]]]]) → retval, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F

and

CV_CALIB_FIX_INTRINSIC Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F matrices are estimated.

PS: I found this answer, but its not applicable for cv2.


Solution

  • If you assign returned values of cv2.stereoCalibrate() to a list and check number of values , you can come to know if it's indeed returning 5 values or something else. That way you can fix your receiving variables and tweak your code accordingly.