apriltag.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016, The Regents of The University of Michigan.
2 All rights reserved.
3 
4 This software was developed in the APRIL Robotics Lab under the
5 direction of Edwin Olson, ebolson@umich.edu. This software may be
6 available under alternative licensing terms; contact the address above.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 The views and conclusions contained in the software and documentation are those
29 of the authors and should not be interpreted as representing official policies,
30 either expressed or implied, of the Regents of The University of Michigan.
31 */
32 
33 #ifndef _APRILTAG_H
34 #define _APRILTAG_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdlib.h>
41 
42 #include "common/matd.h"
43 #include "common/image_u8.h"
44 #include "common/zarray.h"
45 #include "common/workerpool.h"
46 #include "common/timeprofile.h"
47 #include <pthread.h>
48 
49 #define APRILTAG_TASKS_PER_THREAD_TARGET 10
50 
51 struct quad
52 {
53  float p[4][2]; // corners
54 
55  // H: tag coordinates ([-1,1] at the black corners) to pixels
56  // Hinv: pixels to tag
58 };
59 
60 // Represents a tag family. Every tag belongs to a tag family. Tag
61 // families are generated by the Java tool
62 // april.tag.TagFamilyGenerator and can be converted to C using
63 // april.tag.TagToC.
66 {
67  // How many codes are there in this tag family?
68  uint32_t ncodes;
69 
70  // The codes in the family.
71  uint64_t *codes;
72 
73  // how wide (in bit-sizes) is the black border? (usually 1)
74  uint32_t black_border;
75 
76  // how many bits tall and wide is it? (e.g. 36bit tag ==> 6)
77  uint32_t d;
78 
79  // minimum hamming distance between any two codes. (e.g. 36h11 => 11)
80  uint32_t h;
81 
82  // a human-readable name, e.g., "tag36h11"
83  char *name;
84 
85  // some detector implementations may preprocess codes in order to
86  // accelerate decoding. They put their data here. (Do not use the
87  // same apriltag_family instance in more than one implementation)
88  void *impl;
89 };
90 
91 
93 {
94  // reject quads containing too few pixels
96 
97  // how many corner candidates to consider when segmenting a group
98  // of pixels into a quad.
100 
101  // Reject quads where pairs of edges have angles that are close to
102  // straight or close to 180 degrees. Zero means that no quads are
103  // rejected. (In radians).
105 
106  // When fitting lines to the contours, what is the maximum mean
107  // squared error allowed? This is useful in rejecting contours
108  // that are far from being quad shaped; rejecting these quads "early"
109  // saves expensive decoding processing.
111 
112  // When we build our model of black & white pixels, we add an
113  // extra check that the white model must be (overall) brighter
114  // than the black model. How much brighter? (in pixel values,
115  // [0,255]). .
117 
118  // should the thresholded image be deglitched? Only useful for
119  // very noisy images
120  int deglitch;
121 };
122 
123 // Represents a detector object. Upon creating a detector, all fields
124 // are set to reasonable values, but can be overridden by accessing
125 // these fields.
128 {
130  // User-configurable parameters.
131 
132  // How many threads should be used?
133  int nthreads;
134 
135  // detection of quads can be done on a lower-resolution image,
136  // improving speed at a cost of pose accuracy and a slight
137  // decrease in detection rate. Decoding the binary payload is
138  // still done at full resolution. .
140 
141  // What Gaussian blur should be applied to the segmented image
142  // (used for quad detection?) Parameter is the standard deviation
143  // in pixels. Very noisy images benefit from non-zero values
144  // (e.g. 0.8).
145  float quad_sigma;
146 
147  // When non-zero, the edges of the each quad are adjusted to "snap
148  // to" strong gradients nearby. This is useful when decimation is
149  // employed, as it can increase the quality of the initial quad
150  // estimate substantially. Generally recommended to be on (1).
151  //
152  // Very computationally inexpensive. Option is ignored if
153  // quad_decimate = 1.
155 
156  // when non-zero, detections are refined in a way intended to
157  // increase the number of detected tags. Especially effective for
158  // very small tags near the resolution threshold (e.g. 10px on a
159  // side).
161 
162  // when non-zero, detections are refined in a way intended to
163  // increase the accuracy of the extracted pose. This is done by
164  // maximizing the contrast around the black and white border of
165  // the tag. This generally increases the number of successfully
166  // detected tags, though not as effectively (or quickly) as
167  // refine_decode.
168  //
169  // This option must be enabled in order for "goodness" to be
170  // computed.
172 
173  // When non-zero, write a variety of debugging images to the
174  // current working directory at various stages through the
175  // detection process. (Somewhat slow).
176  int debug;
177 
179 
181  // Statistics relating to last processed frame
183 
184  uint32_t nedges;
185  uint32_t nsegments;
186  uint32_t nquads;
187 
189  // Internal variables below
190 
191  // Not freed on apriltag_destroy; a tag family can be shared
192  // between multiple users. The user should ultimately destroy the
193  // tag family passed into the constructor.
195 
196  // Used to manage multi-threading.
198 
199  // Used for thread safety.
200  pthread_mutex_t mutex;
201 };
202 
203 // Represents the detection of a tag. These are returned to the user
204 // and must be individually destroyed by the user.
207 {
208  // a pointer for convenience. not freed by apriltag_detection_destroy.
210 
211  // The decoded ID of the tag
212  int id;
213 
214  // How many error bits were corrected? Note: accepting large numbers of
215  // corrected errors leads to greatly increased false positive rates.
216  // NOTE: As of this implementation, the detector cannot detect tags with
217  // a hamming distance greater than 2.
218  int hamming;
219 
220  // A measure of the quality of tag localization: measures the
221  // average contrast of the pixels around the border of the
222  // tag. refine_pose must be enabled, or this field will be zero.
223  float goodness;
224 
225  // A measure of the quality of the binary decoding process: the
226  // average difference between the intensity of a data bit versus
227  // the decision threshold. Higher numbers roughly indicate better
228  // decodes. This is a reasonable measure of detection accuracy
229  // only for very small tags-- not effective for larger tags (where
230  // we could have sampled anywhere within a bit cell and still
231  // gotten a good detection.)
233 
234  // The 3x3 homography matrix describing the projection from an
235  // "ideal" tag (with corners at (-1,-1), (1,-1), (1,1), and (-1,
236  // 1)) to pixels in the image. This matrix will be freed by
237  // apriltag_detection_destroy.
239 
240  // The center of the detection in image pixel coordinates.
241  double c[2];
242 
243  // The corners of the tag in image pixel coordinates. These always
244  // wrap counter-clock wise around the tag.
245  double p[4][2];
246 };
247 
248 // don't forget to add a family!
250 
251 // add a family to the apriltag detector. caller still "owns" the family.
252 // a single instance should only be provided to one apriltag detector instance.
254 
255 // Tunable, but really, 2 is a good choice. Values of >=3
256 // consume prohibitively large amounts of memory, and otherwise
257 // you want the largest value possible.
259 {
261 }
262 
263 // does not deallocate the family.
265 
266 // unregister all families, but does not deallocate the underlying tag family objects.
268 
269 // Destroy the april tag detector (but not the underlying
270 // apriltag_family_t used to initialize it.)
272 
273 // Detect tags from an image and return an array of
274 // apriltag_detection_t*. You can use apriltag_detections_destroy to
275 // free the array and the detections it contains, or call
276 // _detection_destroy and zarray_destroy yourself.
278 
279 // Call this method on each of the tags returned by apriltag_detector_detect
281 
282 // destroys the array AND the detections within it.
283 void apriltag_detections_destroy(zarray_t *detections);
284 
285 // Renders the apriltag with with 1px white border.
286 // Caller is responsible for calling image_u8_destroy on the image
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif
matd_t * H
Definition: apriltag.h:57
void apriltag_detector_destroy(apriltag_detector_t *td)
Definition: apriltag.c:382
uint32_t nsegments
Definition: apriltag.h:185
void apriltag_detections_destroy(zarray_t *detections)
Definition: apriltag.c:1493
uint32_t ncodes
Definition: apriltag.h:68
void apriltag_detector_add_family_bits(apriltag_detector_t *td, apriltag_family_t *fam, int bits_corrected)
Definition: apriltag.c:330
void * impl
Definition: apriltag.h:88
pthread_mutex_t mutex
Definition: apriltag.h:200
zarray_t * tag_families
Definition: apriltag.h:194
matd_t * Hinv
Definition: apriltag.h:57
uint32_t black_border
Definition: apriltag.h:74
static void apriltag_detector_add_family(apriltag_detector_t *td, apriltag_family_t *fam)
Definition: apriltag.h:258
uint32_t d
Definition: apriltag.h:77
void apriltag_detector_clear_families(apriltag_detector_t *td)
Definition: apriltag.c:338
timeprofile_t * tp
Definition: apriltag.h:182
uint64_t * codes
Definition: apriltag.h:71
float p[4][2]
Definition: apriltag.h:53
image_u8_t * apriltag_to_image(apriltag_family_t *fam, int idx)
Definition: apriltag.c:1505
uint32_t h
Definition: apriltag.h:80
char * name
Definition: apriltag.h:83
uint32_t nquads
Definition: apriltag.h:186
Definition: matd.h:51
Definition: zarray.h:49
void apriltag_detection_destroy(apriltag_detection_t *det)
Definition: apriltag.c:1071
workerpool_t * wp
Definition: apriltag.h:197
Definition: apriltag.h:51
zarray_t * apriltag_detector_detect(apriltag_detector_t *td, image_u8_t *im_orig)
Definition: apriltag.c:1094
uint32_t nedges
Definition: apriltag.h:184
float quad_decimate
Definition: apriltag.h:139
apriltag_detector_t * apriltag_detector_create()
Definition: apriltag.c:348
float decision_margin
Definition: apriltag.h:232
void apriltag_detector_remove_family(apriltag_detector_t *td, apriltag_family_t *fam)
Definition: apriltag.c:324
apriltag_family_t * family
Definition: apriltag.h:209


apriltags2
Author(s): Danylo Malyuta
autogenerated on Fri Oct 19 2018 04:02:32