Skip to main content

PyCalib: Simple Camera Calibration in Python for Beginners

Project description

Simple Camera Calibration in Python for Beginners

This is a collection of algorithms related to multiple view camera calibration in computer vision. Please note that the goal of this package is to provide minimal examples to demonstrate the concept for beginners (i.e., students). For large-scale, realtime, accurate, robust, production-quality implementations, or for implementations for your specific situation, please consult your advisor.

Disclaimer

This is research software and may contain bugs or other issues -- please use it at your own risk. If you experience major problems with it, you may contact us, but please note that we do not have the resources to deal with all issues.

How to use

You can simply install the package by pip as follows.

python3 -m pip install -U pycalib-simple

Or to use the latest version, specifiy the github repository as follows.

python3 -m pip install -U git+https://github.com/nbhr/pycalib.git

Notice that the pip installation does not include examples in ./ipynb/ or tools in ./tools/. To run examples and tools, download the repository explicitly. For example,

  1. Local: You can clone/download this repository to your local PC, and open ./ipynb/*.ipynb files by your local Jupyter (e.g., VSCode + Jupyter plugin).
  2. Colaboratory: You can open each Jupyter notebook directly in Google Colaboratory by clicking the Open In Colab buttons below.
    • Most of them do not run properly as-is, since colab does not clone images used in the Jupyter notebooks. Please upload required files manually. (or run !pip install and !git clone at the beginning of each notebook.)
    • The scripts in ./tools/ are not supposed to run in Colab/Jupyter.

Usage

[Example] Calibration of 15 GoPro cameras

  1. Intrinsic calibration Open In Colab
    • Intrinsic camera calibration from a video of ChAruCo pattern.
    • GoPro fisheye lens distortion is handled by the rational model in OpenCV
  2. 2D keypoint detection Open In Colab
    • ChAruCo corner detection to find 2D-2D corresponding points between cameras.
  3. Extrinsic calibration Open In Colab
    • Extrinsic camera calibartion from 2D-2D correspondences.
  4. Scale / orientation alignment Open In Colab
    • Scale / orientation alignment of the world coordinate system by capturing an AruCo marker on the floor.

Single camera

  1. Intrinsic calibration with charuco images Open In Colab
  2. Intrinsic calibration with chessboard images Open In Colab
    • Zhang's method
  3. Extrinsic calibration w.r.t. a charuco board Open In Colab
    • PnP with ChAruco
  4. Extrinsic calibration w.r.t. a chessboard Open In Colab
    • PnP with chessboard
  5. Intrinsic / Extrinsic calibration with 2D-3D correspondences Open In Colab
    • for non-planar reference objects

Multiple cameras

  1. Multi-view triangulation Open In Colab
    • N-view DLT
  2. Robust brute-force multi-view triangulation Open In Colab
    • Robust but brute-force n-view DLT with occlusion handling and outlier rejection
  3. ChAruco diamond marker detection for 2D-2D correspondences Open In Colab
    • For extrinsic calibration using a ChAruco diamond marker.
    • Also can be used for PnP, i.e., extrinsic calibration w.r.t. the diamond marker
  4. 2-view extrinsic calibration from 2D-2D correspondences Open In Colab
    • Decomposition of the essential matrix to $R$ and $t$.
  5. N-view registration Open In Colab
    • A linear registration of pairwise poses into a single coordinate system
  6. N-view bundle adjustment Open In Colab
    • A non-linear minization of reprojection errors
    • Each camera can spesify the parameters to optimize and to share with each other
  7. N-view time sync Open In Colab
    • GoPro compatible QR time sync pattern generator, detector, and offset estimator
  8. Homography Open In Colab
    • Homography from one camera plane to another
  9. Stereo rectification Open In Colab
    • Horizontal / vertical stereo rectification for multi-view system and triangulation in WCS

Mirror

  1. Mirror-based extrinsic camera calibration Open In Colab
    • Extrinsic calibration of a camera w.r.t. a reference object not directly visible from the camera.
    • This is a general example and does not include a "2D point detection from mirrored images" step.
  2. Display-camera calibration with mirrors Open In Colab
    • How to calibrate a webcam w.r.t. a display using a ChAruCo pattern.

3D-3D

  1. Absolute orientation (or similarity transform) between corresponding 3D points Open In Colab

Circle / Sphere

  1. 3D circle estimation Open In Colab
    • 3D circle center / normal estimation from its 2D projection, i.e., 2D ellipse.
  2. Sphere center estimation Open In Colab
    • 3D sphere center estimation from its 2D projection, i.e., 2D ellipse.
    • For extrinsic calibration using a ball.
    • A color-based ball detection is provided as tools/detect_by_color_gui.py and tools/detect_by_color.py. The former GUI version can be used to sample foreground and background pixel colors, and the latter can be used to process each frame.

If you need to write your own calibration ...

In general, prepare some synthetic dataset, i.e., a toy example, first so that your code can return the exact solution up to the machine epsillon. Then you can try with real data or synthetic data with noise to mimic it.

Also you may want to read Section A6.3 "A sparse Levenberg-Marquardt algorithm" of the textbook "Multiple View Geometry in Computer Vision" by Hartley and Zisserman.

  1. Linear calibration: Use numpy.
  2. Non-linear (including bundule adjustment): Try scipy.optimize.least_squares first.
    1. Implement your objective function as simply as possible. You do not need to consider the computational efficiency at all. "Done is better than perfect."
      • Test with the toy example and make sure that your objective function returns zero for the ground-truth parameter.
    2. If your simple objective function above is unacceptably slow, try the followings in this order.
      1. Ask yourself again before trying to make it faster. Is it really unacceptable? If your calibration can finish in an hour and you do not do it so often, it might be OK for example. "Premature optimization is the root of all evil." (D. Knuth).
      2. Make sure that the calibration runs successfully anyway. In what follows, double-check that the calibration results do not change before and after the code optimization.
      3. Vectorize the computation with numpy, i.e., no for-loops in the objective function.
        • or use numba (e.g. @numba.jit)
      4. If the system is sparse, use jac_sparsity option. It makes scipy.optimize.least_squares much faster even without analitical Jacobian.
      5. Implement the analytical Jacobian. You may want to use maxima to automate the calculation, or you may use JAX or other autodiff solutions for this.
      6. Reimplement in C++ with ceres-solver, g2o, or sba if the computation speed is really important. You can also consider using PyTorch/Tensorflow for GPU-acceleration and autodiff by Theseus or similar libraries.

Contact

Please note that this is research software and may contain bugs or other issues -- please use it at your own risk. If you experience major problems with it, you may contact us, but please note that we do not have the resources to deal with all issues.

Project details


Download files

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

Source Distribution

pycalib_simple-2025.12.5.1.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

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

pycalib_simple-2025.12.5.1-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file pycalib_simple-2025.12.5.1.tar.gz.

File metadata

  • Download URL: pycalib_simple-2025.12.5.1.tar.gz
  • Upload date:
  • Size: 43.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pycalib_simple-2025.12.5.1.tar.gz
Algorithm Hash digest
SHA256 cc91bba4a5d53435061123801b058b1b902f47e8b0117c30f2576f023f50c3eb
MD5 03a616fbfabfda2e01e48acd46c312a2
BLAKE2b-256 b4f96f4641c1e83ed994dd45e3c512b44a847ce82ed43135425ccc42dfa1224d

See more details on using hashes here.

File details

Details for the file pycalib_simple-2025.12.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pycalib_simple-2025.12.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a12d0a3fd0c06587bf48a9ca9ca06f787b8df6fc5894c2fea8e5eed630b9d8f2
MD5 993f3b35d09502f641812f68591edb87
BLAKE2b-256 05683de88ac89b7480e1240c4f43b8ab27dbb1a9f8103c0a599e6ce43ef2f654

See more details on using hashes here.

Supported by

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