Skip to main content

lensboy for camera calibrations

Project description

lensboy

PyPI Python License

Camera calibration for vision engineers. Maximally powerful, minimally complex.

One job: fit camera models and verify the results. OpenCV models when they work, spline-based distortion when they don't.

Many of the techniques in this library were originally developed in mrcal.

Why lensboy

Even for standard OpenCV models, lensboy gives you better calibrations than raw cv2.calibrateCamera (see model comparison notebook):

  • Automatic outlier filtering removes bad detections
  • Target warp estimation compensates for non-flat calibration boards

For cheap or wide-angle lenses where OpenCV's distortion model isn't enough, lensboy offers spline-based models that can capture arbitrary distortion patterns.

Lensboy also offers analysis tools to verify your calibration is actually good.

Quick example

import lensboy as lb

target_points, frames, image_indices = lb.extract_frames_from_charuco(board, imgs)

result = lb.calibrate_camera(
    target_points, frames,
    camera_model_config=lb.OpenCVConfig(
        image_height=h, image_width=w,
    ),
)

result.camera_model.save("camera.json")

Swap the config for a spline model — same API, more flexible:

result = lb.calibrate_camera(
    target_points, frames,
    camera_model_config=lb.PinholeSplinedConfig(
        image_height=h, image_width=w,
    ),
)

Getting started

Read the calibration guide for a full walkthrough - calibrating a camera, verifying the results, and exporting for runtime use.

If you just want to see lensboy in action, see quickstart notebook.

Analysis tools

Plots for residuals, distortion, detection coverage, and model differencing. See the example notebooks.



Install

Full install, with analysis and plotting:

pip install lensboy[analysis]

Minimal install, for loading and using models:

pip install lensboy

Spline models

Spline models use B-spline grids instead of polynomial coefficients, so they can fit lenses that OpenCV's model can't. This approach is inspired by mrcal.

The calibrated model converts to a pinhole model with undistortion maps, so you can use it with any standard pinhole pipeline.

Runtime unproject LUTs

Iterative unprojection can be too slow for some applications. UnprojectLUT caches normalize_points() on a regular pixel grid so that per-pixel queries reduce to a bicubic interpolation. The cache is saved as a directory of metadata.json + xy_grid.npy, loadable from Python or from a small standalone C++ runtime in cpp_runtime/.

import lensboy as lb
from lensboy.analysis import compute_lut_error_heatmap

model = lb.OpenCV.load("camera.json")
lut = model.get_unproject_lut(pixel_stride=32)
lut.save("camera_lut/")

runtime_lut = lb.UnprojectLUT.load("camera_lut/")
rays, valid_mask = runtime_lut.normalize_points(pixel_coords)

heatmap = compute_lut_error_heatmap(runtime_lut, model)

See the unproject LUT guide for sizing, interpolation modes, the file format, and the C++ runtime. There is also a runnable Jupyter notebook.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

lensboy-4.0.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lensboy-4.0.1-cp314-cp314t-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14tmacOS 15.0+ ARM64

lensboy-4.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lensboy-4.0.1-cp314-cp314-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

lensboy-4.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lensboy-4.0.1-cp313-cp313-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

lensboy-4.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lensboy-4.0.1-cp312-cp312-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

lensboy-4.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lensboy-4.0.1-cp311-cp311-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

Details for the file lensboy-4.0.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8e72dcbb2136a86640c5a931fba1ac5813f48a7be36d697c1ec18b4794170124
MD5 1682ff35913b9d721b7956d5d85fc416
BLAKE2b-256 afb2e09539132810678119e42965a49a975f00dd305ff9a6342626300c19006d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp314-cp314t-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp314-cp314t-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 320812234be45ef71255777feab8f16ca697793f605515a4444a80196b7d025e
MD5 97b1a8bfc351af3e26c95ad986191aae
BLAKE2b-256 a109ec9cd9e950f4668791147803984dd6eefae511890a6d991304435ab11cc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp314-cp314t-macosx_15_0_arm64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3be44631e4e388ff886fc1b58bd290a6bd12ca1b697f1630e35576e4dcf17348
MD5 2783516a0eaf03bd833a2055acec58b3
BLAKE2b-256 4449e29032b2232732a8aa41881d7acedce491fc5cd2a234f4924b243bbe4b1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e294c6ccc2ca56e060d4895b8b0efdb785aa5a30e1139aa9b06c83ad0c7716f1
MD5 b26f87101070561aad3e94174aff27a6
BLAKE2b-256 dc46d0d75211a4a44a97d779d990b3563fcf9632dbe3c00084186a59a3c045b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp314-cp314-macosx_15_0_arm64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9b5bc75cb4beee1ce46b136a908a92ae60d3a48a686d8620264ce9929e8874f0
MD5 82f76119a41037aba2eb7484fefdf524
BLAKE2b-256 7fc79859372c4b4048835c413f6852fde1f90a93e75c6d7f3a52e82e0eb58024

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 bc150fc2f8b78bbc9112678f3e0a201df06e72e5794658ea1e830e1d4f3c424f
MD5 d67768578ef09cc67e94da432411c442
BLAKE2b-256 8f7b53c03830175199b338d74a9b831446dd314418e01af18d65c0b6a0559368

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4e0059df37c293d14370caa5d873d3df27412a1b8457209a17e52d431147f7ac
MD5 0bfa3022b87f5a6ee151366a46c8f065
BLAKE2b-256 4eb1959af213d9c1a184b239a44a756bca1eb64877604dc62e3aa91b281eb68a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 99f2b5461518f13e97031eee61ac01c0b20528c52ffc3a0c1b1fea3d107c28ae
MD5 390672b7b6abf7ffa5171c6ac9ca5ebc
BLAKE2b-256 50a018548b2dab35759048f88cf525558299649a6f1d1ea44bba0360e0b33c08

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp312-cp312-macosx_15_0_arm64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 afb8a22eca9609437f35ec18e9ad59c3f9b48665f01a772bdb8422f98348e3d5
MD5 bfc0f81e780ce3d63385ae46c885c9a6
BLAKE2b-256 695112c6a553a7998893885e274f750414e7095e11a31b36c41d09733f4cf662

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lensboy-4.0.1-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a48446090c0ad776572d1e0480ffed87c1e9464b2909694496541a3cbfce57db
MD5 8ad067d21c50eb003c0bb1f776c987c0
BLAKE2b-256 9225018d83f896c9af0f6272aa7d70cbca2c51637d78d591a5d85875382030d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.1-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: wheels.yml on Robertleoj/lensboy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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