This repository contains Python scripts for calibrating individual cameras and performing stereo calibration using OpenCV. The calibration process involves obtaining intrinsic parameters for each camera and determining the transformation between the two cameras in a stereo setup. The parameters are saved as a file stereoMap.xml and in the camera_parameters directory. For examples on using parameters, please refer my repository here.
- Python 3.x
- OpenCV (cv2)
- NumPy
- SciPy
- PyYAML
- Install the required dependencies:
pip install opencv-python numpy scipy- Run the script with the calibration settings file:
python calibrate.py calibration_settings.yamlMake sure to replace calibration_settings.yaml with the actual path to your calibration settings file.
- Save frames for each camera separately using the
save_frames_single_camerafunction.
- Calibrate each camera individually to obtain intrinsic matrices using the
calibrate_camera_for_intrinsic_parametersfunction.
- Save frames for both cameras simultaneously using the
save_frames_two_camsfunction.
- Use paired calibration pattern frames to obtain the rotation and translation between camera0 and camera1 with the
stereo_calibratefunction.
- Save the calibration data, where camera0 defines the world space origin, using the
save_extrinsic_calibration_parametersfunction.
- Optionally, you can define a different origin point and save the calibration data using the
get_world_space_originandget_cam1_to_world_transformsfunctions.
calibrate.py: Main script for camera calibration and stereo calibration.calibration_settings.yaml: YAML file containing calibration settings such as camera parameters, frame dimensions, checkerboard size, etc.camera_parameters/: Directory to store the camera intrinsic and extrinsic calibration parameters.
- The script will generate various output files, including camera intrinsic parameters, stereo calibration parameters, and extrinsic parameters defining the transformation between cameras.
- Make sure to adjust the
calibration_settings.yamlfile to match your specific setup.
- A lot of this code is derived and redeveloped from TemugeB's repository on github
This project is licensed under the Apache 2.0 license.