Skip to main content

OpenCV Camera Calibration

Checkerboard calibration images

A simple tool for checkerboard camera calibration if you are tired of re-writing from the OpenCV docs on camera calibration.

Install

pip install opencv-calibrate 

pypi

Prerequisites

This package relies on ffmpeg, please ensure it is installed. See python ffmpeg for more.

Usage

import opencv_calibrate

# image
image_directory_path = "example_images/"

# image params
checkerboard = (10, 7)
ret, camera_parameters = opencv_calibrate.image(image_directory_path, checkerboard)

# or with video

# video
video_path = "/path/to/video"

# video params
ret, camera_parameters = opencv_calibrate.video(video_path)

Then we can acess the parameters in the camera_parameters object:

# camera intrinsic matrix
camera_matrix = camera_parameters.camera_matrix

# distortion matrix
distortion_matrix = camera_parameters.distortion_matrix

# rotation vectors
rotation_vecs = camera_parameters.rotation_vecs

# translation vectors
translation_vecs = camera_parameters.translation_vecs

# projection error
projection_error = camera_parameters.projection_error

# save parameters
camera_parameters.save("/path/to/dir/")

# load
from opencv_calibrate import CameraParameters
# from npz
camera_parameters.load_from_npz("/path/to/params.npz")
# from yaml
camera_parameters.load_from_yaml("/path/to/params.yaml")

or from the command line (this is also callable by python -m opencv_calibrate.calibrate):

calibrate [-h] [--video VIDEO] [--image_dir IMAGE_DIR] [--output_dir OUTPUT_DIR] [--checkerboard CHECKERBOARD]

Camera calibration of videos and images containing checkerboard run with DEBUG>1 for more outputs

options:
  -h, --help            show this help message and exit
  --video VIDEO         Path to the video file
  --image IMAGE_DIR
                        Path to the directory containing images
  --output_dir OUTPUT_DIR
                        Path to the output directory
  --checkerboard CHECKERBOARD
                        Number of rows, columns and square size (mm) in comma seperated format e.g. "9, 6, 4"

This will output a YAML file with the parameters:

camera_matrix:
- [f_x, 0.0, c_x]
- [0.0, f_y, c_y]
- [0.0, 0.0, 1.0]
distortion_matrix:
- [k1, k2, p1, p2 k3]
projection_error: float

and a .npz numpy file with addition of the extrinsic matrix.

Run with DEBUG environment variable for more outputs, e.g.

DEBUG=1 calibrate --image /path/to/images

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencv_calibrate-0.1.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencv_calibrate-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file opencv_calibrate-0.1.1.tar.gz.

File metadata

  • Download URL: opencv_calibrate-0.1.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for opencv_calibrate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 991f14bb9c0182ebd91f30a2200a61e0013e475438828bdc9c7366d84f68b6f4
MD5 a534aa3cd4725c08393a2ac4b0711b1e
BLAKE2b-256 8fda174874ce18b2c6b3c737f96a8839d090a0a25d594b5b14b81b8b5760d0ea

See more details on using hashes here.

File details

Details for the file opencv_calibrate-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for opencv_calibrate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b60e6ddee84f4a4018638b3fd26994f28a53d732fd3adaa4b6ea72839ce4db25
MD5 a752f53a3f41f9db51e33fe456e6e2c5
BLAKE2b-256 7f1386a7cf22a1847f3180ec12e701ef9052c94ae7048265984b530733b928b9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page