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.
- Capture images of a chessboard pattern using either your webcam or a DJI Tello drone.
- Run the calibration script to detect obtain the camera calibration matrix.
pip install -r requirements.txtThe script captureImage.py is used to capture images from a webcam.
- Press
sto save an image. - Press
qto exit.
By default, it uses camera index 0:
cap = cv.VideoCapture(0)If your webcam is mapped to another index, change that value.
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.
The script getCalibrationMatrix.py is used to compute the camera calibration matrix.
- Loads all
.jpgimages 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
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.pyscript 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.
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.
| 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. |
-
$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)$ .
-
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.
-
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.