# camera-calibration-with-opencv-python **Repository Path**: elorfiniel/camera-calibration-with-opencv-python ## Basic Information - **Project Name**: camera-calibration-with-opencv-python - **Description**: Calibrate web cameras with Opencv-Python. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-11 - **Last Updated**: 2025-06-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Camera Calibration with OpenCV-Python A simple Python project that demonstrates how to calibrate a camera using OpenCV. Eg. a program takes a set of chessboard images as input, calculates the camera matrix and distortion coefficients, and then uses these parameters to undistort images taken with the same camera. This project follows the steps outlined in the OpenCV documentation: [OpenCV-Python Tutorials](https://docs.opencv.org/4.10.0/d6/d00/tutorial_py_root.html). ## Note on Dependencies We use Poetry to manage dependencies (which requires Python 3.8 and above). For further information, see the [Poetry documentation](https://python-poetry.org/docs/). However, the code should run without any issues if you have other versions of Python or other versions of any dependency listed in `pyproject.toml`. Again, this project is for demonstration purposes only. ## Getting Started Please use the following steps to get started. If you prefer to use another method, eg. `conda`, feel free to do so. 1. Clone this repository with `git clone`, or download the ZIP file. ```shell git clone ``` 2. Install Pipx, then install Poetry. ```shell pip install --user pipx pipx install poetry ``` 3. Create a new virtual environment with `venv`. ```shell python -m venv --upgrade-deps venv venv/Scripts/activate.bat # (windows: cmd) venv/Scripts/Activate.ps1 # (windows: pwsh) source venv/bin/activate # (linux / mac) ``` 4. Install the dependencies with `poetry install`. ```shell cd && poetry install ``` ## Chessboard Pattern Use `capture.py` to capture chessboard images. Here's the help message for the script: ```text usage: capture.py [-h] --folder FOLDER [--cap CAP] [--api API] [--w W] [--h H] [--fps FPS] --shape w h name capture chessboard and save frames optional arguments: -h, --help show this help message and exit script options: runtime settings used by top-level scripts --folder FOLDER images will be saved in the images folder under this folder base options: calibration name, camera settings and pattern shape name calibration name --cap CAP capture device for cv2.VideoCapture, eg. camera index --api API capture api for cv2.VideoCapture, eg. CAP_ANY --w W capture width, in pixels --h H capture height, in pixels --fps FPS capture framerate --shape w h pattern shape, # of squares, eg. ('w', 'h') ``` ## Camera Parameters Use `calibrate.py` to calibrate the camera parameters. Note that we invoke the `intrinsic` subcommand or the `extrinsic` subcommand accordingly to calibrate the intrinsics or the extrinsics. ```text usage: calibrate.py [-h] --folder FOLDER [--cap CAP] [--api API] [--w W] [--h H] [--fps FPS] --shape w h {intrinsic,extrinsic} ... name calibrate camera with chessboard images optional arguments: -h, --help show this help message and exit script options: runtime settings used by top-level scripts --folder FOLDER images are saved in the images folder under this folder subcommands: calibration type, each has its own options {intrinsic,extrinsic} specify type to see additional help intrinsic calibrate camera intrinsics extrinsic calibrate camera extrinsics base options: calibration name, camera settings and pattern shape name calibration name --cap CAP capture device for cv2.VideoCapture, eg. camera index --api API capture api for cv2.VideoCapture, eg. CAP_ANY --w W capture width, in pixels --h H capture height, in pixels --fps FPS capture framerate --shape w h pattern shape, # of squares, eg. ('w', 'h') ``` ### Extra Options for `intrinsic` Subcommand ```text usage: calibrate.py intrinsic [-h] [--wsize WSIZE] [--mm MM] calibrate camera intrinsics with chessboard images optional arguments: -h, --help show this help message and exit --wsize WSIZE half of the side length of the search window, see cv2.cornerSubPix --mm MM side length of each square, in millimeters ``` ### Extra Options for `extrinsic` Subcommand ```text usage: calibrate.py extrinsic [-h] --intrinsic INTRINSIC [--wsize WSIZE] [--mm MM] calibrate camera extrinsics with chessboard images optional arguments: -h, --help show this help message and exit --intrinsic INTRINSIC, --in-params INTRINSIC intrinsic calibration results, in JSON format --wsize WSIZE half of the side length of the search window, see cv2.cornerSubPix --mm MM side length of each square, in millimeters ```