Anipose lib
aniposelib calibrates groups of cameras and turns 2D points seen by several cameras into 3D. It is the library behind Anipose, and you can also use it on its own.
This branch is the PyTorch version, published on PyPI as aniposelib-pytorch. It runs on the GPU when one is
available, and it still imports as aniposelib.
Installing
pip install aniposelib-pytorch
If you need a particular CUDA build of PyTorch, install that first (see https://pytorch.org/get-started/locally/).
A few features need extra packages, which you can add with pip extras:
aniposelib-pytorch[deepcharuco]: a learned ChArUco board detector, which finds boards that OpenCV misses.aniposelib-pytorch[vggt]: VGGT, which can guess camera positions straight from images.aniposelib-pytorch[sync]: reading audio from video files, for synchronising cameras.aniposelib-pytorch[all]: all of the above.
Don't install it next to the classic aniposelib package (the numpy version, 0.8.x). Both provide the
aniposelib import, so one would overwrite the other. If your project lists aniposelib as a requirement, replace it
with aniposelib-pytorch. If both end up installed anyway, import aniposelib stops with an error; fix it with:
pip uninstall -y aniposelib aniposelib-pytorch && pip install aniposelib-pytorch
What you can do with it
Most projects need some of these seven steps. Each one is a single function.
| I want to... | Function |
|---|---|
| calibrate my cameras with a calibration board (or another object of known shape) | calibrate_from_board |
| calibrate my cameras from the animals or people in the videos, without a board | calibrate_from_points |
| put a calibration into real units (mm) or line it up with the floor or an older calibration | estimate_scale |
| check whether a calibration is good, or still good, or whether a camera was bumped | evaluate_calibration |
| line up cameras that weren't recording in sync | estimate_offsets |
| turn 2D keypoints from several cameras into 3D | reconstruct_3d |
| work out which animal is which when several are in view | associate_views |
A typical lab setup with a ChArUco board looks like this:
import aniposelib as al
board = al.CharucoBoard(7, 5, square_length=25, marker_length=18.75, units='mm')
# 1. calibrate the cameras from videos of the board
cgroup, result = al.calibrate_from_board([['cam1.mp4'], ['cam2.mp4'], ['cam3.mp4']], board,
cam_names=['cam1', 'cam2', 'cam3'],
out='calibration.toml')
print(result.summary())
# 2. later, turn 2D keypoints into 3D
# points2d has shape (cameras, frames, keypoints, 2), with NaN where a keypoint wasn't found
recon = al.reconstruct_3d(cgroup, points2d, scores=scores)
points3d = recon.points3d # (frames, keypoints, 3)
Every function returns a result that tells you how it went:
result.verdictis'ok','warn'or'fail'.result.reasonssays, in plain words, what was wrong.result.summary()prints a short table of the checks.
A bad result comes back as 'fail' with a reason; it doesn't raise an error. You shouldn't need to tune thresholds:
they're worked out from how noisy your data is and how big your camera setup is, so the same call works whether
your setup is measured in millimetres or metres.
The workflow guide walks through each step with examples.
The lower-level toolbox
The seven functions are built from a larger set of tools, which you can use directly when you need more control: camera models, board detection, triangulation, bundle adjustment, quality reports, scale and alignment, and synchronisation. Some common ones:
from aniposelib import CameraGroup
cgroup = CameraGroup.load('calibration.toml')
cgroup.dump('calibration.toml')
p3d = cgroup.triangulate(p2d) # simple triangulation, p2d has shape (cameras, points, 2)
res = cgroup.triangulate_robust(p2d) # ignores views that disagree with the others
err = cgroup.reprojection_error(p3d, p2d)
cgroup.bundle_adjust_robust(p2d) # refine the calibration on your points
report = cgroup.report(p2d) # per-camera errors, including leave-one-camera-out
Anipose itself uses the classic calibration call, which still works the same way:
cgroup = CameraGroup.from_names(['A', 'B', 'C'])
error, rows = cgroup.calibrate_videos([['A.mp4'], ['B.mp4'], ['C.mp4']], board)
Where to find the rest:
aniposelib.init: ways to get a first guess of the camera positions (from a board, from points, from VGGT).aniposelib.quality: calibration checks.aniposelib.scale: scale and alignment.aniposelib.syncandaniposelib.stba: camera synchronisation.aniposelib.matching: matching animals across cameras.aniposelib.intrinsics: picking a lens model.aniposelib.geometryandaniposelib.triangulation: the batched maths underneath.
A note on data shapes. 2D points are arrays with the camera as the first axis, (cameras, points, 2) or
(cameras, frames, keypoints, 2), with NaN for missing points. If you pass numpy arrays you get numpy arrays back;
if you pass torch tensors you get torch tensors back.
Upgrading
Version 1.1 removed the file-format converters (aniposelib.io) and a few helpers that were specific to one project.
Version 1.0 changed several defaults compared with 0.9. CHANGELOG.md lists every change and how to
get the old behaviour back.
The Anipose documentation has a tutorial.
Metadata
Release files for aniposelib-pytorch 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aniposelib_pytorch-1.1.0.tar.gz | 492.8 kB | Without provenance | Details for aniposelib_pytorch-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aniposelib_pytorch-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for aniposelib_pytorch-1.1.0-py3-none-any.whl |
Total release size: 896.7 kB
Release files / aniposelib_pytorch-1.1.0.tar.gz
| Download URL | aniposelib_pytorch-1.1.0.tar.gz |
|---|---|
| Size | 492.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e7f73380792da3c809c11e1bee772acb648360dfe1130c18f53ed2fc1958c51
|
|
BLAKE2b-256 checksum How to use checksums |
311e53b1c39d22313bf10fce70acd52f9a6bea80ac7b4f5479419f6d291ed933
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / aniposelib_pytorch-1.1.0-py3-none-any.whl
| Download URL | aniposelib_pytorch-1.1.0-py3-none-any.whl |
|---|---|
| Size | 403.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2aa7c99b7f9496dd1cf7e4c10029c562f52f919e27d85cfed3dc021fbdb81a12
|
|
BLAKE2b-256 checksum How to use checksums |
b753fe0d16e8d7e27d3a66de12c8bac8debe940704aa233fef0c38589ef2f1f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Security for aniposelib-pytorch 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.