Giter VIP home page Giter VIP logo

camera-calibration-opencv's Introduction

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

camera-calibration-opencv's People

Contributors

alfieroddan avatar

Stargazers

 avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.