<jupyter_start><jupyter_text>Create calibration data based on chessboard stereo images Description: This code will go through all the stereo images found in the dataset folder, or whichever photo contains the images, and will create calibration data based on them. THe resulting calibration data will be stored in a folder called "calib_result"  Cell Block 1 Description: This cell block just imports all the necessary libraries.<jupyter_code>import os
import cv2
import numpy as np
from stereovision.calibration import StereoCalibrator
from stereovision.calibration import StereoCalibration
from stereovision.exceptions import ChessboardNotFoundError

print("Libraries Imported")<jupyter_output><empty_output><jupyter_text>Cell Block 2 Description: Here I set my variables which include photo width and heigh, the rows and columns of the chessboard, the size of the squares on the chessboard in centimeters, and the directory where the images will be read from.<jupyter_code># Global variables preset
total_photos = 50
photo_width = 640
photo_height = 480
img_width = 640
img_height = 480
image_size = (img_width,img_height)

# Chessboard parameters
rows = 6
columns = 9
square_size = 1.8#2.5

calibrator = StereoCalibrator(rows, columns, square_size, image_size)
counter = 0
directory = "dataset"

print("Variables Set")<jupyter_output><empty_output><jupyter_text>Cell Block 3 Description: The following loop will then go through each pair of photos, verify once more that there is a chessboard found within them, and then proceed to store calibration data using the StereoCalibrator class.<jupyter_code>while counter <= total_photos:
    print(counter)
    image_pathL = os.path.join(directory, str(counter) + '_Left.jpg')
    image_pathR = os.path.join(directory, str(counter) + '_Right.jpg')
    print(image_pathL)
    print(image_pathR)
    if os.path.isfile(image_pathL) and os.path.isfile(image_pathR):
        imgLeft = cv2.imread(image_pathL,1)
        imgRight = cv2.imread(image_pathR,1)
        #print(imgLeft)
        retR, cornersR = cv2.findChessboardCorners(imgLeft, (9,6),None)
        retL, cornersL = cv2.findChessboardCorners(imgRight, (9,6),None)
    # If found, add object points, image points (after refining them)
        if retL == True and retR == True:
            print("Chessboard found")
            calibrator._get_corners(imgLeft)
            calibrator._get_corners(imgRight)
            calibrator.add_corners((imgLeft, imgRight), False)
    counter += 1<jupyter_output><empty_output><jupyter_text>Cell Block 4 Description: After all the data is stored in the class, I call the StereoCalibrator calibrate_cameras() function and then proceed to export the final clibrated data to a folder called "calib_result"<jupyter_code>print ('Starting calibration... It can take several minutes!')
calibration = calibrator.calibrate_cameras()
calibration.export('calib_result')
print ('Calibration complete!')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07461174881836596, 'fraction_numerical': 0.012491559756921, 'mean_word_length': 5.1092783505154635, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '299633', 'license': 'MIT', 'n_tokens_mistral': 917, 'n_tokens_neox': 859, 'n_words': 294, 'path': '4- Stereo Calibration.ipynb', 'repo_name': 'npapyan/StereoVision', 'size': '2962'}