Ask Your Question

camera Calibration in opencv (python stereo camera). Error:too many value to unpack

asked 2013-10-31 04:30:44 -0500

Katri gravatar image

updated 2013-11-01 10:57:38 -0500

berak gravatar image

Hi, I am trying the stereo calibration in opencv using python. I am using python version 2.7.1 and openCV version 2.4.2 When i run the code, I get an error saying too many values to unpack. Below is my code:

objPoints = []
pointCounts = hor*ver
R = [8]
T = [8]
R1 = []
R2 = []
P2 =[]
objectPoints = []
imgPoints1 = []
imgPoints2 = []
imagePoints2 = []
imagePoints1 = []

while ((len(imagePoints1) < hor*ver) and (len(imagePoints2)< hor*ver)): #hor x ver

ret,imgr  =
ret,imgl  =
grey_imgr = cv2.cvtColor(imgr, cv.CV_BGR2GRAY)
grey_imgl = cv2.cvtColor(imgl, cv.CV_BGR2GRAY)
ret, cornersr =cv2.findChessboardCorners(grey_imgr,dims)
ret, cornersl =cv2.findChessboardCorners(grey_imgl,dims)
cv2.imshow("chessboard", grey_imgr)
cv2.imshow("chessboard1", grey_imgl)

objPoints = np.zeros((hor*ver,3), np.float32)
objPoints[:,:2] = np.mgrid[0:hor,0:ver].T.reshape(-1,2)

if cv.WaitKey(-1) == 32:

    print len(imagePoints1)
    i = i+1;

    if cv2.waitKey(10) == 27:

objectPoints = [np.asarray(x)
                   for x in objectPoints]
imagePoints1 = [np.asarray(x)
                for x in imagePoints1]
imagePoints2 = [np.asarray(x)
              for x in imagePoints2]

if( len(imagePoints1[0])== len(imagePoints2[0]) == len(objectPoints[0]) == len(objectPoints)==      len(imagePoints2) == len(imagePoints1) ) :
 print len(imagePoints1[0])

 cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F =          cv2.stereoCalibrate(objectPoints, imagePoints1, imagePoints2, (320,240))
  print R

  cv.StereoRectify(cameraMatrix1, cameraMatrix2, distCoeffs1, distCoeffs2,(imgr.width,imgr.height), R, T, R1, R2, P1, P2, Q, CV_CALIB_ZERO_DISPARITY, -1, (0, 0))
 print  Q

and the error I get is :

Traceback (most recent call last): File "", line 82, in <module> cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = cv2.stereoCalibrate(objectPoints, imagePoints1, imagePoints2, (320,240)) ValueError: too many values to unpack

I am giving an array of objectpoints each of which in turn is an array of points.

Any help in this issue will be appreciated. Thanks a lot.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2013-11-01 10:51:47 -0500

MahamKhan gravatar image

I think you are returning so many values.Check the documentation of cv2.stereocalibrate. Although R,T,E,F and others are output matrices but they must be written inside like this:

Python: cv.StereoCalibrate(objectPoints, imagePoints1, imagePoints2, pointCounts, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T, E=None, F=None, term_crit=(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 30, 1e-6), flags=CV_CALIB_FIX_INTRINSIC) →None NOTE: The order may be changed for cv2 (this is cv )

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2013-10-31 04:30:44 -0500

Seen: 902 times

Last updated: Nov 01 '13