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.2-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.2-cp314-cp314t-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14tmacOS 15.0+ ARM64

lensboy-4.0.2-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.2-cp314-cp314-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

lensboy-4.0.2-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.2-cp313-cp313-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

lensboy-4.0.2-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.2-cp312-cp312-macosx_15_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

lensboy-4.0.2-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.2-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.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 938b2d3afb216e01e142b9308971e8da5941c16e976b3aa8bf535f7a67a8cff3
MD5 74aa29a37dac53f68a96eeb91a72a0db
BLAKE2b-256 d5fe9921eccfc0df469d8e50df8bc6f0a087e30ed0e48eb37014bd063acca3b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp314-cp314t-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp314-cp314t-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b52a0a94b30c277fe588cdc327c102f03082f831618f1ba6ca4f105caf479273
MD5 c9b2041c46f326e5085529a6ff1f4ecc
BLAKE2b-256 021e8ec1196b04b5a45efbb35d30d44a37b87c065d21475d827f3ba2d0e7a5e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 477553dd61a1b966ded97fdfbe4bb9daff26696defd5cc5c28a9639a33b9b101
MD5 c9c960356a4f635ffdc7562ad565113f
BLAKE2b-256 4fb9345f8357449e3a59bfd1025fc8126dbd0d36d8a76c9505e36ddab08ee571

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e855f8eff22d633c33130e1380a19d10cd389bca95806c90e29d5bd822d63ceb
MD5 681989d38629ab877ba0668f3a01efd3
BLAKE2b-256 2909c44797217556faa46ca771f166ad1836a445f007f4c1f36ce7250036fd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aed7bfe2c41396c7e87b7496af49b97026b1c8b8910d344d1933e0df3635eda2
MD5 bdc5c9de4db21a836318c81f3f2068f0
BLAKE2b-256 abe06a50538cc7d46885ac7ad35ce7a90109bd3c1d7de2f5cd57e7598c851ad4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 aabc292831cf6a6e1fe6479f7d12073ba14cace9bf923028cf33a331a53426ea
MD5 57625334b2e52109b3f8f07927b5be9c
BLAKE2b-256 9194721ff1384c72ce8186f78c9cdd025169ac1ad879c56c22b5909f074cabcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bdaba95dee7b96d0d9241b4a103bebc31155f1c94006555ef1cd2c523c037180
MD5 0395d89feaf38baa15da06dfad5f74e8
BLAKE2b-256 4a26720d9554d942f06111cd5009a075e8e5a7afecb08950afae4ab7314814b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e6452d25c9eb2b7e31dd9cfa2b66efb81d7e6b6e103850762552e0de9ca57bf8
MD5 2084a378bbf5b1ce322d43b14d71ffbf
BLAKE2b-256 863442e203925b602e8857386a7d7185dcdf53b00e2535932bfa136f2c9279b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a3b0f6f5ca63120fd07f41f6cb924e552a42d0edcf83e8683350ee724e72230d
MD5 43d2cf75a127116c4d7e21b8102906a7
BLAKE2b-256 84e20203b4d95cf0ac4bca7b327c0fb674117aecb2e9e8750ad3afb2d4aa0808

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 bdc688977676f7c4ff3a12f66eefd0267b0715fc1997e16531f7ec84247122b1
MD5 84efbd607c0c6d3bc2673a4f38949476
BLAKE2b-256 980709158e4460f95c465e45e851974ff5da74c244cad136bde5632462ed1046

See more details on using hashes here.

Provenance

The following attestation bundles were made for lensboy-4.0.2-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