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

Uploaded CPython 3.14tmacOS 15.0+ ARM64

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

Uploaded CPython 3.14macOS 15.0+ ARM64

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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12macOS 15.0+ ARM64

lensboy-4.0.0-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.0-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.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lensboy-4.0.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 92e8570d777fee571dead6c1c6102a900c81dc9b3f6647598cf580ce8b96883e
MD5 7b158826f556bc73d9533a39ae4ee185
BLAKE2b-256 9a59766711dd357fcdfcc98edd9ee856b9a50b890da1410dfe2b5d2b83879ee4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp314-cp314t-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 bd7e32d2664ac4668230f7ca17a9c08b3c21265985856a36dc22bd040c56d4e1
MD5 61db4634d795e94755e0813a122bf3c7
BLAKE2b-256 489276b5044db859ada9c50d6d01a2a2d3c456980ee1ff52a03f1da8e5267276

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 843ad33d8add5aa02622c8c743d501b8ea3692ef04133ce07fde86e7ea442043
MD5 b9716a892ac13a902c3218446ee0a3c2
BLAKE2b-256 7ac333244bd819f078f5af7f74aadd9498e0fd30a3414b60ca570531cbca326e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 25ca244f740dbd99b48d55e330adffef62c16382e6375b67dfdad6fcb421e408
MD5 bd10b3c9c8fc759bbf5c93183a81a384
BLAKE2b-256 f2a97edcf8aa38f6ec655469886185c5d1c28c8ef3d09415344929b3789d377d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d561438ff1731e03d57bbdcf3a0d65efaab312bb531c9733bc1255ca1c6fdf9e
MD5 6cbd7d1b201d3ea244bc5c310c0f0340
BLAKE2b-256 bde55db2f8d06b229cce41b4007811351d4fa5733214fb01a7d8a8fa4fd77839

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9a156fa024d0d5cb318e9df4c3d2850dd64b24ecd74781dea591749277904a17
MD5 ec31bcd03d1137ce763225973f22ef36
BLAKE2b-256 a70867c3c44bc6e1363f3342be1532fa9bdb749d93c0e0d8f635666d4367b368

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 10a142bc58240f762664ae8ab141199630d5c1ed7e6254a7f11d3edee1a8e9fa
MD5 9f742ad7577e52a413033f6f2c8c6b86
BLAKE2b-256 d4875bd636a7f6772572b5e6b74eef2a163a2ac9ee12d676658817335890a0e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7e3423ed3258180fb1ad4ac7fe55ed98428db5bb5fea335e1087ce73eacfef37
MD5 9c4d8b9f58b043af1198311926a8ba13
BLAKE2b-256 d43acc5ddef08c7dd62ffb00b3f7e9b738cade7b025a88be46604c670642f3e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c007261428fd1a3fd24d1d6a901f4020175dd140c18ce2889b79f8a801d1a647
MD5 0a54e899eb1f6c87b3fa44fe90cbb77c
BLAKE2b-256 09e4f9002e46547aebabb2439eca9b0e2c9c4c9d62eae769f399af70bfc8e843

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lensboy-4.0.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 52fcdfc03bc58d18abda4bcd637446a36cab66bd4ed6096c81f3ffab2ce9af87
MD5 968e62f0989b45a8a06713b1d19b9609
BLAKE2b-256 04c9b5e8b2183ae127d65891556589e7e5ee4ca5cfd7bb82b272fa02de76308f

See more details on using hashes here.

Provenance

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