Skip to main content

Python SDK for applying CalibrX calibration exports to undistort images.

Project description

CalibrX SDK

Python Status OpenCV NumPy CLI License

CalibrX

The official Python SDK for the calibrx.io camera calibration platform.

Use CalibrX to bring platform-generated calibration results into your local computer vision workflows. Export a calibration from calibrx.io, load it in Python, and apply the same camera model, distortion coefficients, and undistortion settings in scripts, notebooks, production pipelines, or command line tools.

Features

  • Load CalibrX JSON and YAML calibration exports.
  • Support pinhole, pinhole_wide, and fisheye camera models.
  • Apply saved undistortion settings such as balance and fov_scale.
  • Override balance and fov_scale at runtime for local experiments.
  • Use either Python arrays, image files, or the CLI.
  • Work in scripts, notebooks, CI jobs, and batch processing pipelines.

Install

pip install calibrx

Quick Start

from calibrx import undistort_file

undistort_file(
    "input.jpg",
    "rectified_calibration.json",
    "output.jpg",
)

The calibration export decides the camera model and default undistortion settings. You can override them when needed:

from calibrx import undistort_file

undistort_file(
    "input.jpg",
    "rectified_calibration.yaml",
    "output.jpg",
    balance=0.5,
    fov_scale=1.0,
)

Notebook Usage

import cv2
import matplotlib.pyplot as plt
from calibrx import load_calibration, undistort

image = cv2.imread("input.jpg")
calibration = load_calibration("rectified_calibration.json")

result = undistort(image, calibration)

plt.figure(figsize=(14, 6))

plt.subplot(1, 2, 1)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title("Original")
plt.axis("off")

plt.subplot(1, 2, 2)
plt.imshow(cv2.cvtColor(result.image, cv2.COLOR_BGR2RGB))
plt.title("Undistorted")
plt.axis("off")

plt.show()

If Jupyter cannot import calibrx, install a kernel from the same environment:

source .venv/bin/activate
python -m pip install ipykernel
python -m ipykernel install --user --name calibrx --display-name "Python (calibrx)"

Python API

from calibrx import (
    Calibration,
    load_calibration,
    undistort,
    undistort_image,
    undistort_file,
)

Load a Calibration

calibration = load_calibration("calibration.json")

print(calibration.camera_model)
print(calibration.image_size)
print(calibration.K)
print(calibration.D.reshape(-1))
print(calibration.balance)

Undistort an Image Array

import cv2
from calibrx import load_calibration, undistort

image = cv2.imread("input.jpg")
calibration = load_calibration("rectified_calibration.json")

result = undistort(image, calibration)

cv2.imwrite("output.jpg", result.image)
print(result.camera_matrix)
print(result.roi)

result.roi is the OpenCV valid-pixel ROI for pinhole models. Fisheye undistortion does not return an ROI, so the value is None.

Return Only the Image

from calibrx import undistort_image

undistorted = undistort_image("input.jpg", "rectified_calibration.json")

Handle Errors

from calibrx import CalibrationFormatError, UndistortionError

try:
    result = undistort("input.jpg", "rectified_calibration.json")
except CalibrationFormatError as exc:
    print(f"Invalid calibration export: {exc}")
except UndistortionError as exc:
    print(f"Could not undistort image: {exc}")

CLI Usage

Single image:

calibrx undistort input.jpg rectified_calibration.json output.jpg

Fisheye tuning:

calibrx undistort input.jpg rectified_calibration.json output.jpg \
  --balance 0.5 \
  --fov-scale 1.0

Batch a directory:

calibrx undistort ./frames rectified_calibration.json ./undistorted --glob "*.jpg"

The CLI prints every output path it writes.

Supported Exports

The SDK supports calibration exports from calibrx.io:

  • calibration.json
  • calibration.yaml
  • rectified_calibration.json
  • rectified_calibration.yaml

It expects OpenCV-ready intrinsics:

  • intrinsics.camera_matrix, or named fx, fy, cx, cy parameters.
  • intrinsics.distortion_coefficients, or named distortion parameters such as k1, k2, p1, p2, and k3.
  • camera_model: pinhole, pinhole_wide, or fisheye.

See docs/export-format.md for the full schema.

Development

For local development from this repository:

python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

Run the test suite:

python -m pytest

Build and validate the package:

python -m build
python -m twine check dist/*

Run a quick local smoke test:

python - <<'PY'
import numpy as np
from calibrx import Calibration, undistort

print("calibrx import ok")

image = np.zeros((32, 48, 3), dtype=np.uint8)
calibration = Calibration.from_dict({
    "camera_model": "pinhole",
    "image_width": 48,
    "image_height": 32,
    "camera_matrix": [[40, 0, 24], [0, 40, 16], [0, 0, 1]],
    "distortion_coefficients": [0, 0, 0, 0, 0],
})

result = undistort(image, calibration)
print(result.image.shape)
print(result.camera_matrix.shape)
PY

License

MIT. See LICENSE.

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

calibrx-0.1.0.tar.gz (60.1 kB view details)

Uploaded Source

Built Distribution

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

calibrx-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file calibrx-0.1.0.tar.gz.

File metadata

  • Download URL: calibrx-0.1.0.tar.gz
  • Upload date:
  • Size: 60.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for calibrx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4bf2e7860f9d2d8463303af0b71bf4b8e6211299ec858f66b44f5bcd0bd353c2
MD5 3e9f1fc3c43ce27fae7682626f17f43e
BLAKE2b-256 e692192d07803e1abbca436ca305e128a7fa1860688999a47f3eddb81248881b

See more details on using hashes here.

Provenance

The following attestation bundles were made for calibrx-0.1.0.tar.gz:

Publisher: publish.yml on Nassimos07/calibrx

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

File details

Details for the file calibrx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: calibrx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for calibrx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 487a66ec9525b9948eab99d3f30cb06d95b8a537ab729794398519d2bfb27584
MD5 b4c37d6a35e86720a01cda72501013fc
BLAKE2b-256 aee868198c0db151031120256e995184bf7c931da366baf5a8f63ae92e2ae2f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for calibrx-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Nassimos07/calibrx

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