Camera Calibration with OpenCV

Vizualization

Table of Contents

  1. Overview
  2. Installation
  3. Project Structure
  4. Execution
  5. Features
  6. Output

Overview

This repository contains a Python script to calibrate a camera using a set of chessboard images. It leverages OpenCV for image processing and calibration, as well as NumPy and Matplotlib for data management and visualization.

Installation

# Clone the repository
$ git clone https://github.com/<your-github-username>/camera-calibration.git
# Navigate to the project folder.
$ cd camera-calibration
# Create the Conda environment.
$ conda env create -f environment.yml
# Activate the new environment.
$ conda activate xvision

Project Structure

camera-calibration/
│
├── main_script.py          # Main Python script
├── images/                 # Directory for chessboard images
├── info/                   # Optional: Directory for output files
└── environment.yml         # Conda environment file

Execution

  1. Ensure your chessboard images for calibration are inside the images/ folder.
  2. Open a terminal and navigate to the project directory.
  3. Run the main script:
$ python calibration.py

Features

  • Automatic Chessboard Detection: Reads images from images/ and detects chessboard corners.
  • Camera Calibration: Calibrates the camera using detected points.
  • Parameter Persistence: Saves calibration parameters in both text and .npz formats.
  • Calibration Validation: Displays a sample undistorted image and calculates the error rate of the calibration.

Output

info/calibration.npz: This NumPy file contains the camera matrix, distortion coefficients, rotation vectors, and translation vectors.