Skip to content

About

Camera calibration toolkit for extracting and saving camera matrices in .txt format, with built-in modules for various video sources including the DJI Tello and OpenCV webcams.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Camera Calibration

Camera calibration toolkit for working with chessboard images. It can capture frames from a local webcam or a DJI Tello drone, detect the inner chessboard corners, and use those points to estimate the camera calibration matrix.


How it works

  1. Capture images of a chessboard pattern using either your webcam or a DJI Tello drone.
  2. Run the calibration script to detect obtain the camera calibration matrix.

Requirements

pip install -r requirements.txt

Capture Images

Capture from webcam

The script captureImage.py is used to capture images from a webcam.

  • Press s to save an image.
  • Press q to exit.

By default, it uses camera index 0:

cap = cv.VideoCapture(0)

If your webcam is mapped to another index, change that value.

Capture from DJI Tello

The script telloImage.py is used to capture images from a DJI Tello drone. As it uses the captureImage.py script, the same key bindings apply.


Calibration Script

The script getCalibrationMatrix.py is used to compute the camera calibration matrix.

  • Loads all .jpg images in the project folder. You can change the image format in the script if needed.
  • Looks for the 13x10 squares by default. But you can change the inner-corner count in the script if your chessboard has a different size.

If findChessboardCorners cannot detect the pattern:

  • make sure the inner-corner count is correct
  • use good lighting
  • keep the board fully visible in the image
  • avoid blur and strong reflections
  • capture images from different angles

Image Capture Recommendations

In order to obtain the most optimal results consider the following points when capturing your images:

  • Use 20 images or more to obtain an accurate reading
  • Eliminate or retake images that are blurry or distorted
  • Use getCalibrationMatrix.py script to filter out images whose corners seem misaligned
  • Make sure to take images that follow the requirements in the section Calibration Script

Note: The calibration matrix in this repo is for the djitello camera, but you can use your own images to compute a new calibration matrix.


Camera Calibration Output Guide

The calibration script outputs a configuration file that contains the intrinsic parameters and distortion characteristics of the camera. The values are obtained using OpenCV's cv2.calibrateCamera() function. The results can then be used to undistort other images or video feeds taken with the same camera.

File Contents & Variable Definitions

Variable Type Description
ret float Overall RMS Re-projection Error (in pixels). Measures how accurately the estimated parameters project 3D points back into 2D pixel coordinates. Lower is better (target: < 1.0 px).
mtx 3x3 Matrix Camera Intrinsic Matrix. Maps 3D spatial points relative to the camera to 2D image coordinates.
dist 1x5 Matrix Distortion Coefficients. Lens-specific values [k1, k2, p1, p2, k3] used to mathematically correct lens curvature.
rvecs tuple of 3x1 Arrays Rotation Vectors. The 3D orientation of the target relative to the camera for each individual calibration image.
tvecs tuple of 3x1 Arrays Translation Vectors. The 3D physical position (X, Y, Z) of the target relative to the camera for each individual calibration image.

Detailed Parameter Description

1. Camera Intrinsic Matrix (mtx)

$$\text{mtx} = \begin{bmatrix} f_x & 0 & c_x \ 0 & f_y & c_y \ 0 & 0 & 1 \end{bmatrix}$$

  • $f_x, f_y$ (Focal Lengths): The focal length of the camera lens expressed in pixel units along the X and Y axes. For cameras with square pixels, $f_x \approx f_y$.
  • $c_x, c_y$ (Optical Center / Principal Point): The pixel coordinates where the camera's optical axis intersects the image sensor. For a $960 \times 720$ frame, this point is typically near $(480, 360)$.

2. Distortion Coefficients (dist)

$$\text{dist} = \begin{bmatrix} k_1 & k_2 & p_1 & p_2 & k_3 \end{bmatrix}$$

  • Radial Distortion ($k_1, k_2, k_3$): Corrects "barrel" or "pincushion" warping caused by spherical lens geometry (rays bending more near the edges of the lens).
  • Tangential Distortion ($p_1, p_2$): Corrects minor alignment errors caused by the physical lens sensor not being mounted perfectly parallel to the image sensor plane.

3. Diagnostic & Pose Data (ret, rvecs, tvecs)

  • ret (Reprojection Error): Used primarily to validate calibration quality. Values below $1.0\text{ px}$ indicate high precision.
  • rvecs & tvecs (Extrinsics): Specific to the training dataset pictures. These are generally ignored during live flight/streaming unless estimating the exact position and orientation of a 3D object relative to the camera.

About

Camera calibration toolkit for extracting and saving camera matrices in .txt format, with built-in modules for various video sources including the DJI Tello and OpenCV webcams.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages