forked from AprilRobotics/apriltag
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python3 wrapper thanks to Dima Kogan (AprilRobotics#42)
- Loading branch information
Showing
5 changed files
with
575 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
AprilTag detector | ||
|
||
SYNOPSIS | ||
|
||
import cv2 | ||
import numpy as np | ||
from apriltag import apriltag | ||
|
||
imagepath = '/tmp/tst.jpg' | ||
image = cv2.imread(imagepath, cv2.IMREAD_GRAYSCALE) | ||
detector = apriltag("tag36h11") | ||
|
||
detections = detector.detect(image) | ||
|
||
print("Saw tags {} at\n{}". \ | ||
format([d['id'] for d in detections], | ||
np.array([d['center'] for d in detections]))) | ||
|
||
----> Saw tags [3, 5, 7, 8, 10, 10, 14] at | ||
[[582.42911184 172.90587335] | ||
[703.32149701 271.50587376] | ||
[288.1462089 227.01502779] | ||
[463.63679264 227.91185418] | ||
[ 93.88534443 241.61109765] | ||
[121.94062798 237.97010936] | ||
[356.46940849 260.20169159]] | ||
|
||
DESCRIPTION | ||
|
||
The AprilTags visual fiducial system project page is here: | ||
https://april.eecs.umich.edu/software/apriltag | ||
|
||
This is a Python class to provide AprilTags functionality in Python programs. To | ||
run the detector you | ||
|
||
1. Construct an object of type apriltag.apriltag() | ||
|
||
2. Invoke the detect() method on this object | ||
|
||
The detect() method takes a single argument: an image array. The return value is | ||
a tuple containing the detections. Each detection is a dict with keys: | ||
|
||
- id: integer identifying each detected tag | ||
|
||
- center: pixel coordinates of the center of each detection | ||
|
||
- lb-rb-rt-lt: pixel coordinates of the 4 corners of each detection. The order | ||
is left-bottom, right-bottom, right-top, left-top | ||
|
||
- 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. | ||
|
||
- 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.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
AprilTag detector | ||
|
||
SYNOPSIS | ||
|
||
import cv2 | ||
import numpy as np | ||
from apriltag import apriltag | ||
|
||
imagepath = '/tmp/tst.jpg' | ||
image = cv2.imread(imagepath, cv2.IMREAD_GRAYSCALE) | ||
detector = apriltag("tag36h11") | ||
|
||
detections = detector.detect(image) | ||
|
||
print("Saw tags {} at\n{}". \ | ||
format([d['id'] for d in detections], | ||
np.array([d['center'] for d in detections]))) | ||
|
||
----> Saw tags [3, 5, 7, 8, 10, 10, 14] at | ||
[[582.42911184 172.90587335] | ||
[703.32149701 271.50587376] | ||
[288.1462089 227.01502779] | ||
[463.63679264 227.91185418] | ||
[ 93.88534443 241.61109765] | ||
[121.94062798 237.97010936] | ||
[356.46940849 260.20169159]] | ||
|
||
DESCRIPTION | ||
|
||
The AprilTags visual fiducial system project page is here: | ||
https://april.eecs.umich.edu/software/apriltag | ||
|
||
This is a Python class to provide AprilTags functionality in Python programs. To | ||
run the detector you | ||
|
||
1. Construct an object of type apriltag.apriltag() | ||
|
||
2. Invoke the detect() method on this object | ||
|
||
The constructor takes a number of arguments: | ||
|
||
- family: a string for the tag type we're detecting. This argument is required. | ||
If an invalid string is given, the known list of tag families will be | ||
reported. At the time of this writing the known families are: | ||
|
||
- "tag36h11" | ||
- "tag25h9" | ||
- "tag16h5" | ||
- "tagCircle21h7" | ||
- "tagCircle49h12" | ||
- "tagStandard41h12" | ||
- "tagStandard52h13" | ||
- "tagCustom48h12" | ||
|
||
All the other arguments are optional: | ||
|
||
- Nthreads: how many threads the detector should use. Default is 1 | ||
|
||
- maxhamming: max number of corrected bits. Larger values guzzle RAM. Default is | ||
1 | ||
|
||
- decimate: 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. Default is 1.0 | ||
|
||
- blur: What Gaussian blur should be applied to the segmented image (used for | ||
quad detection?) Parameter is the standard deviation in pixels. Very noisy | ||
images benefit from non-zero values (e.g. 0.8). Default is 0.0 | ||
|
||
- refine_edges: 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. Very computationally inexpensive. Option is ignored if | ||
decimate == 1. Default is True | ||
|
||
- debug: When non-zero, write a variety of debugging images to the current | ||
working directory at various stages through the detection process. (Somewhat | ||
slow). Default is False | ||
|
||
The detect() method takes a single argument: an image array |
Oops, something went wrong.