From Tekkotsu Wiki
AprilTags are an implementation of Augmented Reality Tags from Edwin Olson's APRIL Laboratory at the University of Michigan. They are visual markers designed for robust detection by machines.
See AprilTag: A robust and flexible multi-purpose fiducial system for a description of the algorithm. See the ARTag.net web site for information about earlier implementations of the augmented reality tag idea, and the ARToolKit page for information about a currently popular implementation. Here are some YouTube demo videos. And here are the two 2004 technical reports by Mark Fiala describing his ARTag implementation: NRC-47166 and NRC-47419. There is also a book about use of ARTag: Augmented Reality: A Practical Guide.
Printing Your Own AprilTags
The tag16h5 and tag36h11 tag families can be found in /usr/local/Tekkotsu/Vision/AprilTags. To print out your own tags, first cd to one of those directories. Then:
- Run gimp on one of the png files, e.g., "gimp tag16h5_00000.png"
- From the pulldown menu, select Image > Scale Image
- Set the units to inches and the size to your desired size (typically 3 to 5 inches)
- Set the Interpolation mode to None (this is crucial)
- Click on the Scale button
- From the pulldown menu, select File > Save As
- Save the image as a PostScript file, e.g., /tmp/tag0.ps
- Send the PostScript file to your printer
Running the TagTest Demo
Follow the AprilTags install instructions to install the TagTest demo. To run the demo, type /usr/local/april/bin/tagtest. Click on the "Debug" checkbox and then control-right click on the display and go to "Select Buffers" to call up a menu of display options. Click on the "Detach" menu item. You can also click-and-drag in the 3D display (the right half of the main window) to rotate the view.
A few sample 36h11 tags are shown at right. this is the tag family that the TagTest demo recognizes. The name 36h11 indicates that these are 36 bit tags (6x6 array) with a minimum Hamming distance of 11 bits between codes. There are 518 tags in this tag family.
Using AprilTags With Tekkotsu
How the Algorithm Works
The algorithm has nine steps:
- Convert the image to floating point grayscale (pixel values between 0.0 and 1.0) and apply a Gaussian blur.
- Calculate the local gradient (magnitude and direction) at each pixel.
- Generate a list of edges, grouping connected pixels with similar directions together. An edge is present if the magnitude of the gradient for both pixels is significantly above zero.
- Create clusters from the edges.
- Loop over the clusters, fitting lines called Segments.
- For each Segment, find segments that begin where this segment ends.
- Search all connected segments to find loops of length 4, called Quads. Each quad represents the black border around a tag candidate.
- Decode the quads by looking at the pixels inside the border to see if they represent a valid tag code, and generate a list of TagDetections
- Search for overlapping TagDetections and take the best ones (lowest Hamming distance or largest perimeter); discard the rest.
Generating Your Own AprilTags
To generate .png files for each tag in the 36h11 family, use the following commands:
cd /usr/local/april/java export CLASSPATH=/usr/local/april/java/april.jar java april.tag.TagFamily april.tag.Tag36h11 /tmp/tag36h11
You can then use a program like gv to display /tmp/tag36h11/alltags.ps, or use gimp or display to show the mosaic.png file or one of the individual tag .png files.
To generate a new tag family, such as the 16h5 family (the default family used by Tekkotsu), use the following commands:
cd /usr/local/april/java export CLASSPATH=/usr/local/april/java/april.jar java april.tag.TagFamilyGenerator 16 5 >/tmp/Tag16h5.java
Install the file Tag16h5.java in /usr/local/april/java/src/april/tag and then use the instructions above to generate the alltags.ps file and individual .png files.