Python bindings for the Apriltags library
Project description
pyapriltags: Python bindings for the Apriltags library
These are Python bindings for the Apriltags 3 library developed by AprilRobotics. Inspired by the Apriltags2 bindings by Matt Zucker. Forked from dt-apriltags.
The original library is published with a BSD 2-Clause license.
Installation
The easy way
You can install using pip
(or pip3
for Python 3):
pip install pyapriltags
And if you want a particular release, add it like this:
pip install pyapriltags@v3.3.0
Build it yourself
Clone this repository and navigate in it. Then initialize the Apriltags submodule:
$ git submodule init
$ git submodule update
Build the Apriltags C library and embed the newly-built library into the pip wheel.
$ make build
The new wheel will be available in the directory dist/
.
You can now install the wheel
pip install pyapriltags-VERSION-py3-none-ARCH.whl
NOTE: based on the current VERSION
of this library and your OS, together with the architecture of your CPU ARCH
, the filename above varies.
Release wheels
All the wheels built inside dist/
can be released (pushed to Pypi.org) by running the command
make upload
Release all
Use the following command to build and release wheels for Python 3 and CPU architecture amd64
, aarch64
and arm32v7
.
make release-all
Usage
Some examples of usage can be seen in the test.py
file.
The Detector
class is a wrapper around the Apriltags functionality. You can initialize it as following:
at_detector = Detector(searchpath=['apriltags'],
families='tag36h11',
nthreads=1,
quad_decimate=1.0,
quad_sigma=0.0,
refine_edges=1,
decode_sharpening=0.25,
debug=0)
The options are:
Option | Default | Explanation |
---|---|---|
families | 'tag36h11' | Tag families, separated with a space |
nthreads | 1 | Number of threads |
quad_decimate | 2.0 | Detection of quads can be done on a lower-resolution image, improving speed at a cost of pose accuracy and a slight decrease in detection rate. Decoding the binary payload is still done at full resolution. Set this to 1.0 to use the full resolution. |
quad_sigma | 0.0 | What Gaussian blur should be applied to the segmented image. Parameter is the standard deviation in pixels. Very noisy images benefit from non-zero values (e.g. 0.8) |
refine_edges | 1 | When non-zero, the edges of the each quad are adjusted to "snap to" strong gradients nearby. This is useful when decimation is employed, as it can increase the quality of the initial quad estimate substantially. Generally recommended to be on (1). Very computationally inexpensive. Option is ignored if quad_decimate = 1 |
decode_sharpening | 0.25 | How much sharpening should be done to decoded images? This can help decode small tags but may or may not help in odd lighting conditions or low light conditions |
searchpath | ['apriltags'] | Where to look for the Apriltag 3 library, must be a list |
debug | 0 | If 1, will save debug images. Runs very slow |
Detection of tags in images is done by running the detect
method of the detector:
tags = at_detector.detect(img, estimate_tag_pose=False, camera_params=None, tag_size=None)
If you also want to extract the tag pose, estimate_tag_pose
should be set to True
and camera_params
([fx, fy, cx, cy]
) and tag_size
(in meters) should be supplied. The detect
method returns a list of Detection
objects each having the following attributes (note that the ones with an asterisks are computed only if estimate_tag_pose=True
):
Attribute | Explanation |
---|---|
tag_family | The family of the tag. |
tag_id | The decoded ID of the tag. |
hamming | How many error bits were corrected? Note: accepting large numbers of corrected errors leads to greatly increased false positive rates. NOTE: As of this implementation, the detector cannot detect tags with a Hamming distance greater than 2. |
decision_margin | A measure of the quality of the binary decoding process: the average difference between the intensity of a data bit versus the decision threshold. Higher numbers roughly indicate better decodes. This is a reasonable measure of detection accuracy only for very small tags-- not effective for larger tags (where we could have sampled anywhere within a bit cell and still gotten a good detection.) |
homography | The 3x3 homography matrix describing the projection from an "ideal" tag (with corners at (-1,1), (1,1), (1,-1), and (-1, -1)) to pixels in the image. |
center | The center of the detection in image pixel coordinates. |
corners | The corners of the tag in image pixel coordinates. These always wrap counter-clock wise around the tag. |
pose_R* | Rotation matrix of the pose estimate. |
pose_t* | Translation of the pose estimate. |
pose_err* | Object-space error of the estimation. |
Custom layouts
If you want to use a custom layout, you need to create the C source and header files for it and then build the library again. Then use the new libapriltag.so
library. You can find more information on the original Apriltags repository.
Developer notes
The wheel is built inside a Docker container. The Dockerfile in the root of this repository is a template for the build environment. The build environment is based on ubuntu:latest
and python3 is installed on the fly.
The make build
command will create the build environment if it does not exist before building the wheel.
Once the build environment (Docker image) is ready, a Docker container is launched with the following configuration:
- the root of this repository mounted to
/apriltag
; - the directory
dist/
is mounted as destination directory under/out
;
The building script from assets/build.sh
will be executed inside the container. The build steps are:
- configure a cmake build in
/builds/<arch>
from the apriltag library from submoduleapriltags/
- run cmake build
- copy so/.dylib/.dll library file to
/dist/<arch>
(inside the container) - repeat above steps for:
win64
,macos arm64
,macos x86_64
,linux x86_64
,linux aarch64
,linux armv7l
- build python wheel (the .so library is embedded as
package_data
) - copy wheel file to
/out
(will pop up indist/
outside the container)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pyapriltags-3.3.0.3-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65753ea23a0b72b52c268363570f4029bb230d19989c678a461ba72588707ce0 |
|
MD5 | 876dbc091e6aef75242637ed7a210aaa |
|
BLAKE2b-256 | 2d523ae3b45e1ff168e46e477ccc73b4d34ace879c114bb848b93c309aaf87df |
Hashes for pyapriltags-3.3.0.3-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 937a60b18ea8c695eb2546c8f956a7eac2a3b56cd38d265701e4a35806bd9dc1 |
|
MD5 | 9e12055c33579de1ec021ba303e10881 |
|
BLAKE2b-256 | 5223058160b6f4d085672604d533f5ffbbbcdfb4a5f00165d0b0327160141a24 |
Hashes for pyapriltags-3.3.0.3-py3-none-manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb6ea0620a888a042940ad69850f5925ac8cc9e00524da9655b344f7133f3b3 |
|
MD5 | 7c95c4c496159532ea591221e082d1f7 |
|
BLAKE2b-256 | 4ac643128a4daa96609cd33fd25f2fecb7b28fb54b4da705fef3d00f5d35ae0b |
Hashes for pyapriltags-3.3.0.3-py3-none-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b20469a61989e4c3fa155ed4a39a785f5498369ca1a84e5623da10ba9e24dec7 |
|
MD5 | 0c8faf54013b1b006acd1c326aa9574d |
|
BLAKE2b-256 | 68175d4f52a3bc1e7dd42eded983e08557e986acb00e4b804013af4237b601f3 |
Hashes for pyapriltags-3.3.0.3-py3-none-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd8831e01c5a1910655d7f4781f4535fff2d4d4a96ee1874b70cf6fda7e43b03 |
|
MD5 | 59f1f7eddc1ef69fdbe9407e72e0591b |
|
BLAKE2b-256 | fff8e16a5c2cefbeb905bba9a8cf36e0d23311e76310c5b2195571ad81048653 |
Hashes for pyapriltags-3.3.0.3-py3-none-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5dc0e0e0e75910c2302f940f0850bcf1e28c9500bc47b49d95ade195461ae63 |
|
MD5 | 69e87d055dca6f696037f0b80ff287b8 |
|
BLAKE2b-256 | 0dadffa0ab3a15fba2e869bdd9e0ba9573b35e9f8aad80a8958987db36e61485 |
Hashes for pyapriltags-3.3.0.3-py3-none-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f55ccd25301b7aff416dfee45026a50589e5d5bd12f546a884c936850f1e64e2 |
|
MD5 | 333cdaf395e24102eb4fe1c27868d1cf |
|
BLAKE2b-256 | e7d28a735d74e4fa66a940bd70981596cbe5f0511c50c7e0cc3cf556100883ec |