1 | // This file is part of OpenCV project. |
2 | // It is subject to the license terms in the LICENSE file found in the top-level directory |
3 | // of this distribution and at http://opencv.org/license.html. |
4 | // |
5 | // Copyright (C) 2013-2016, The Regents of The University of Michigan. |
6 | // |
7 | // This software was developed in the APRIL Robotics Lab under the |
8 | // direction of Edwin Olson, ebolson@umich.edu. This software may be |
9 | // available under alternative licensing terms; contact the address above. |
10 | // |
11 | // The views and conclusions contained in the software and documentation are those |
12 | // of the authors and should not be interpreted as representing official policies, |
13 | // either expressed or implied, of the Regents of The University of Michigan. |
14 | |
15 | // limitation: image size must be <32768 in width and height. This is |
16 | // because we use a fixed-point 16 bit integer representation with one |
17 | // fractional bit. |
18 | |
19 | #ifndef _OPENCV_APRIL_QUAD_THRESH_HPP_ |
20 | #define _OPENCV_APRIL_QUAD_THRESH_HPP_ |
21 | |
22 | #include "unionfind.hpp" |
23 | #include "zmaxheap.hpp" |
24 | #include "zarray.hpp" |
25 | |
26 | namespace cv { |
27 | namespace aruco { |
28 | |
29 | static inline uint32_t u64hash_2(uint64_t x) { |
30 | return uint32_t((2654435761UL * x) >> 32); |
31 | } |
32 | |
33 | struct uint64_zarray_entry{ |
34 | uint64_t id; |
35 | zarray_t *cluster; |
36 | |
37 | struct uint64_zarray_entry *next; |
38 | }; |
39 | |
40 | struct pt{ |
41 | // Note: these represent 2*actual value. |
42 | uint16_t x, y; |
43 | float theta; |
44 | int16_t gx, gy; |
45 | }; |
46 | |
47 | struct remove_vertex{ |
48 | int i; // which vertex to remove? |
49 | int left, right; // left vertex, right vertex |
50 | |
51 | double err; |
52 | }; |
53 | |
54 | struct segment{ |
55 | int is_vertex; |
56 | |
57 | // always greater than zero, but right can be > size, which denotes |
58 | // a wrap around back to the beginning of the points. and left < right. |
59 | int left, right; |
60 | }; |
61 | |
62 | struct line_fit_pt{ |
63 | double Mx, My; |
64 | double Mxx, Myy, Mxy; |
65 | double W; // total weight |
66 | }; |
67 | |
68 | /** |
69 | * lfps contains *cumulative* moments for N points, with |
70 | * index j reflecting points [0,j] (inclusive). |
71 | * fit a line to the points [i0, i1] (inclusive). i0, i1 are both (0, sz) |
72 | * if i1 < i0, we treat this as a wrap around. |
73 | */ |
74 | void fit_line(struct line_fit_pt *lfps, int sz, int i0, int i1, double *lineparm, double *err, double *mse); |
75 | |
76 | int err_compare_descending(const void *_a, const void *_b); |
77 | |
78 | /** |
79 | 1. Identify A) white points near a black point and B) black points near a white point. |
80 | |
81 | 2. Find the connected components within each of the classes above, |
82 | yielding clusters of "white-near-black" and |
83 | "black-near-white". (These two classes are kept separate). Each |
84 | segment has a unique id. |
85 | |
86 | 3. For every pair of "white-near-black" and "black-near-white" |
87 | clusters, find the set of points that are in one and adjacent to the |
88 | other. In other words, a "boundary" layer between the two |
89 | clusters. (This is actually performed by iterating over the pixels, |
90 | rather than pairs of clusters.) Critically, this helps keep nearby |
91 | edges from becoming connected. |
92 | **/ |
93 | int quad_segment_maxima(const DetectorParameters &td, int sz, struct line_fit_pt *lfps, int indices[4]); |
94 | |
95 | /** |
96 | * returns 0 if the cluster looks bad. |
97 | */ |
98 | int quad_segment_agg(int sz, struct line_fit_pt *lfps, int indices[4]); |
99 | |
100 | /** |
101 | * return 1 if the quad looks okay, 0 if it should be discarded |
102 | * quad |
103 | **/ |
104 | int fit_quad(const DetectorParameters &_params, const Mat im, zarray_t *cluster, struct sQuad *quad); |
105 | |
106 | |
107 | void threshold(const Mat mIm, const DetectorParameters ¶meters, Mat& mThresh); |
108 | |
109 | |
110 | zarray_t *apriltag_quad_thresh(const DetectorParameters ¶meters, const Mat & mImg, |
111 | std::vector<std::vector<Point> > &contours); |
112 | |
113 | void _apriltag(Mat im_orig, const DetectorParameters &_params, std::vector<std::vector<Point2f> > &candidates, |
114 | std::vector<std::vector<Point> > &contours); |
115 | |
116 | }} |
117 | #endif |
118 | |