'**SUMMARY**
Stereo Calibration is a way in which you obtain the parameters that will allow you to calculate 3D information of the scene.
Once both the camera\'s are initialized.
Press [Space] once chessboard is identified in both the camera\'s.
Press [esc] key to exit the calibration process.
**PARAMETERS**
* camLeft - Left camera index.
* camRight - Right camera index.
* nboards - Number of samples or multiple views of the chessboard in different positions and orientations with your stereo camera.
* chessboard - A tuple of Cols, Rows in the chessboard (used for calibration).
* gridsize - chessboard grid size in real units
* WinSize - This is the window resolution.
**RETURNS**
A tuple of the form (CM1, CM2, D1, D2, R, T, E, F) on success
CM1 - Camera Matrix for left camera,
CM2 - Camera Matrix for right camera,
D1 - Vector of distortion coefficients for left camera,
D2 - Vector of distortion coefficients for right camera,
R - Rotation matrix between the left and the right camera coordinate systems,
T - Translation vector between the left and the right coordinate systems of the cameras,
E - Essential matrix,
F - Fundamental matrix
**EXAMPLE**
>>> StereoCam = StereoCamera()
>>> calibration = StereoCam.StereoCalibration(1,2,nboards=40)
**Note**
Press space to capture the images.'

def stereoCalibration(self, camLeft, camRight, nboards=30, chessboard=(8, 5), gridsize=0.027, WinSize=(352, 288)):

    count = 0
    n1 = 'Left'
    n2 = 'Right'
    try:
        captureLeft = cv.CaptureFromCAM(camLeft)
        cv.SetCaptureProperty(captureLeft, cv.CV_CAP_PROP_FRAME_WIDTH, WinSize[0])
        cv.SetCaptureProperty(captureLeft, cv.CV_CAP_PROP_FRAME_HEIGHT, WinSize[1])
        frameLeft = cv.QueryFrame(captureLeft)
        cv.FindChessboardCorners(frameLeft, chessboard)
        captureRight = cv.CaptureFromCAM(camRight)
        cv.SetCaptureProperty(captureRight, cv.CV_CAP_PROP_FRAME_WIDTH, WinSize[0])
        cv.SetCaptureProperty(captureRight, cv.CV_CAP_PROP_FRAME_HEIGHT, WinSize[1])
        frameRight = cv.QueryFrame(captureRight)
        cv.FindChessboardCorners(frameRight, chessboard)
    except:
        print 'Error    Initialising    the    Left    and    Right    camera'
        return None
    imagePoints1 = cv.CreateMat(1, ((nboards * chessboard[0]) * chessboard[1]), cv.CV_64FC2)
    imagePoints2 = cv.CreateMat(1, ((nboards * chessboard[0]) * chessboard[1]), cv.CV_64FC2)
    objectPoints = cv.CreateMat(1, ((chessboard[0] * chessboard[1]) * nboards), cv.CV_64FC3)
    nPoints = cv.CreateMat(1, nboards, cv.CV_32S)
    CM1 = cv.CreateMat(3, 3, cv.CV_64F)
    CM2 = cv.CreateMat(3, 3, cv.CV_64F)
    D1 = cv.CreateMat(1, 5, cv.CV_64F)
    D2 = cv.CreateMat(1, 5, cv.CV_64F)
    R = cv.CreateMat(3, 3, cv.CV_64F)
    T = cv.CreateMat(3, 1, cv.CV_64F)
    E = cv.CreateMat(3, 3, cv.CV_64F)
    F = cv.CreateMat(3, 3, cv.CV_64F)
    while True:
        frameLeft = cv.QueryFrame(captureLeft)
        cv.Flip(frameLeft, frameLeft, 1)
        frameRight = cv.QueryFrame(captureRight)
        cv.Flip(frameRight, frameRight, 1)
        k = cv.WaitKey(3)
        cor1 = cv.FindChessboardCorners(frameLeft, chessboard)
        if cor1[0]:
            cv.DrawChessboardCorners(frameLeft, chessboard, cor1[1], cor1[0])
            cv.ShowImage(n1, frameLeft)
        cor2 = cv.FindChessboardCorners(frameRight, chessboard)
        if cor2[0]:
            cv.DrawChessboardCorners(frameRight, chessboard, cor2[1], cor2[0])
            cv.ShowImage(n2, frameRight)
        if (cor1[0] and cor2[0] and (k == 32)):
            print count
            for i in range(0, len(cor1[1])):
                cv.Set1D(imagePoints1, (((count * chessboard[0]) * chessboard[1]) + i), cv.Scalar(cor1[1][i][0], cor1[1][i][1]))
                cv.Set1D(imagePoints2, (((count * chessboard[0]) * chessboard[1]) + i), cv.Scalar(cor2[1][i][0], cor2[1][i][1]))
            count += 1
            if (count == nboards):
                cv.DestroyAllWindows()
                for i in range(nboards):
                    for j in range(chessboard[1]):
                        for k in range(chessboard[0]):
                            cv.Set1D(objectPoints, ((((i * chessboard[1]) * chessboard[0]) + (j * chessboard[0])) + k), ((k * gridsize), (j * gridsize), 0))
                for i in range(nboards):
                    cv.Set1D(nPoints, i, (chessboard[0] * chessboard[1]))
                cv.SetIdentity(CM1)
                cv.SetIdentity(CM2)
                cv.Zero(D1)
                cv.Zero(D2)
                print 'Running    stereo    calibration...'
                del camLeft
                del camRight
                cv.StereoCalibrate(objectPoints, imagePoints1, imagePoints2, nPoints, CM1, D1, CM2, D2, WinSize, R, T, E, F, flags=(cv.CV_CALIB_SAME_FOCAL_LENGTH | cv.CV_CALIB_ZERO_TANGENT_DIST))
                print 'Done.'
                return (CM1, CM2, D1, D2, R, T, E, F)
        cv.ShowImage(n1, frameLeft)
        cv.ShowImage(n2, frameRight)
        if (k == 27):
            print 'ESC    pressed.    Exiting.    WARNING:    NOT    ENOUGH    CHESSBOARDS    FOUND    YET'
            cv.DestroyAllWindows()
            break
