cv2.stereocalibrate() error about "cameraMatrix" not being a numerical tuple
<p>I'm working on estimating distance from stereo cameras. I  am using python 2.7.11 and OpenCV 3.1 versions.I calibrated every camera separately and found intrinsic parameters. the problem is that when I use cv2.stereocalibtare() function in the way stated in OpenCV documents I get the error: "TypeError: cameraMatrix1 is not a numerical tuple".</p>

<p>the code looks like this :</p>

<pre><code>stereo_criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS, 100, 1e-5)
ret_stereo, R, T, E, F = cv2.stereoCalibrate(objpointsL, imgpointsL, imgpointsR, grayL.shape[::-1],mtxL, distcoeffL, mtxR, distcoeffR, criteria=stereo_criteria, flags=cv2.CALIB_FIX_INTRINSIC)
</code></pre>

<p>I thought that changing the camera matrix into tuple using tuple() function  might work. it didn't change anything. and then I thought the problem might be the version of opencv  that I'm using so I changed it into 2.4.13 but that didn't change anything also. after all these tries I thought I let the stereocalibrate() do the camera matrix and distortion coefficient estimation itself without any single camera calibration. </p>

<p>the code looked like this:</p>

<pre><code>stereo_criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS, 100, 1e-5)
stereocalib_retval, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = cv2.stereoCalibrate(objpointsL,imgpointsL,imgpointsR,grayL.shape, criteria=stereo_criteria)
</code></pre>

<p>but it gets an error saying: "TypeError: Required argument 'distCoeffs1' (pos 5) not found"
I just can't figure out why this function is not working. All I want is to calculate the R, T, E, F values </p>

<p><strong>UPDATE:</strong> For the last error I tried this:</p>

<pre><code>stereocalib_retval, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = cv2.stereoCalibrate(objpointsL,
                                                                                                         imgpointsL,
                                                                                                         imgpointsR,
                                                                                                         mtxL,
                                                                                                         distcoeffL,
                                                                                                         mtxR,
                                                                                                         distcoeffR,
                                                                                                         image_size,
                                                                                                         criteria=stereocalib_criteria,
                                                                                                         flags=stereocalib_flags)
</code></pre>

<p>and it worked. although putting cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2 were not needed ( and are actually equal to mtxL,discoeffL,mtxR,discoeffR respectively ) omitting them was causing error for me. The first problem still remains.</p>

<p>I appreciate your help</p>

<p>Masood Saber</p>

<p>Problem fixed.I used the lines below and errors were fixed.</p>

<pre><code>`cameraMatrix1 =None
cameraMatrix2 = None
distCoeffs1 = None
distCoeffs2 = None
R =None
T = None
E = None
F = None
retval, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = cv2.stereoCalibrate(objpointsL,imgpointsL, imgpointsR,cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2,(w,h), R, T, E, F, flags= stereocalib_flags, criteria = stereocalib_criteria)`
</code></pre>

python opencv camera calibration