This project performs camera calibration using a single checkerboard image. The script detects checkerboard corners, calibrates the camera, and undistorts the image. Calibration parameters and results are saved for future use.
- Detects checkerboard corners using OpenCV.
- Computes camera intrinsic matrix and distortion coefficients.
- Saves calibration parameters (
camera_calibration.npz
). - Undistorts the original image and saves the result (
undistorted_image.jpg
).
- Python 3.x
- OpenCV (cv2)
- NumPy
Ensure your checkerboard pattern has 8 inner corners per row and 6 per column (i.e., 9x7 total squares). Modify checkerboard_dims
if your pattern differs.
-
Clone the repository or download the script.
-
Place your checkerboard image in a known location and update the
image_path
variable in the script:image_path = r"D:\Path\To\Your\Image.jpg"
-
Install the required packages:
pip install -r requirements.txt
-
Run the script:
python camera_calibration.py
π Output
-
camera_calibration.npz
β Numpy archive containing:- Camera matrix
- Distortion coefficients
- Rotation and translation vectors
-
undistorted_image.jpg
β Corrected image without lens distortion.
π Notes
- If the checkerboard corners are not detected, verify the pattern, lighting, and image quality.
- You can use multiple images to improve calibration accuracy by looping through a directory.