Convert README to README.rst for Github co-hosting
[sparrow.git] / edges.h
blob50989f170c5b28410013f608c3d37fda4ca2563a
1 #ifndef __SPARROW_EDGES_H__
2 #define __SPARROW_EDGES_H__
4 /* CAMERA_ADJUST_TIME to wair for iris to adjust after find screen flash */
5 #define CAMERA_ADJUST_TIME 10
6 #define SAFETY_LAG 3
7 #define SIG_WEIGHT 2
9 /* for discarding outliers */
10 #define OUTLIER_RADIUS 7
11 #define OUTLIER_THRESHOLD (OUTLIER_RADIUS * OUTLIER_RADIUS)
13 #define BAD_PIXEL 0xffff
15 #define FL_DUMPFILE "/tmp/edges.dump"
17 #define COLOUR_QUANT 1
18 #define COLOUR_MASK (0xff >> COLOUR_QUANT)
20 /*if squared error between observed error and predicted error exceeds this,
21 ignore the observation */
22 #define CORNER_EXACT_THRESHOLD 16
24 /*a corner based on fewer than this number of projects cannot be considered
25 settled */
26 #define MIN_CORNER_ESTIMATES 5
28 /* nice big word. acos(1.0 - MAX_NONCOLLINEARITY) = angle of deviation. This
29 is used when lining up known points to estimte the position of lost ones.
30 0.005: 5.7 degrees, 0.01: 8.1, 0.02: 11.5, 0.04: 16.3, 0.08: 23.1
31 1 pixel deviation in 32 -> ~ 1/33 == 0.03 (if I understand correctly)
33 #define MAX_NONCOLLINEARITY 0.02
35 typedef enum corner_status {
36 CORNER_UNUSED,
37 CORNER_PROJECTED,
38 CORNER_EXACT,
39 CORNER_SETTLED,
40 } corner_status_t;
42 typedef enum edges_state {
43 EDGES_FIND_NOISE,
44 EDGES_WAIT_FOR_LINES_LOCK,
45 EDGES_FIND_LINES,
46 EDGES_FIND_CORNERS,
47 EDGES_WAIT_FOR_PLAY,
49 EDGES_NEXT_STATE,
50 } edges_state_t;
52 #define USE_FLOAT_COORDS 1
54 #if USE_FLOAT_COORDS
55 typedef float coord_t;
56 typedef float coord_sum_t;
57 #define QUANTISE_DELTA(d)((d) / LINE_PERIOD)
59 #else
60 /* the mesh is stored in a fixed point notation.*/
61 #define SPARROW_FIXED_POINT 9
63 typedef int coord_t;
64 typedef gint64 coord_sum_t;
65 #define QUANTISE_DELTA(d)(((d) + LINE_PERIOD / 2) / LINE_PERIOD)
67 #endif
69 typedef struct sparrow_estimator_s {
70 int x1;
71 int y1;
72 int x2;
73 int y2;
74 int x3;
75 int y3;
76 //int mul; /* estimate: x1,y1 + mul * diff */
77 } sparrow_estimator_t;
79 typedef struct sparrow_corner_s {
80 coord_t x;
81 coord_t y;
82 /*dyr -> dy to next point right
83 dxd ->dx to next point down */
84 coord_t dxr;
85 coord_t dyr;
86 coord_t dxd;
87 coord_t dyd;
88 corner_status_t status;
89 } sparrow_corner_t;
91 typedef struct sparrow_voter_s {
92 coord_t x;
93 coord_t y;
94 guint32 signal;
95 } sparrow_voter_t;
97 typedef struct sparrow_point_s {
98 coord_t x;
99 coord_t y;
100 } sparrow_point_t;
102 typedef struct sparrow_cluster_s {
103 int n;
104 sparrow_voter_t voters[8];
105 } sparrow_cluster_t;
108 typedef union sparrow_signal_s {
109 guint16 v_signal;
110 guint16 h_signal;
111 } sparrow_signal_t;
114 typedef struct sparrow_intersect_s {
115 guint16 lines[2];
116 guint16 signal[2];
117 } sparrow_intersect_t;
119 typedef struct sparrow_line_s {
120 gint offset;
121 sparrow_axis_t dir;
122 gint index;
123 } sparrow_line_t;
125 /*condensed version of <struct sparrow_find_lines_s> for saving: contains no
126 pointers or other unnecessary things that might vary in size across
127 architectures. */
128 typedef struct sparrow_fl_condensed {
129 gint32 n_vlines;
130 gint32 n_hlines;
131 } sparrow_fl_condensed_t;
133 typedef struct sparrow_find_lines_s {
134 sparrow_line_t *h_lines;
135 sparrow_line_t *v_lines;
136 sparrow_line_t **shuffled_lines;
137 int current;
138 int n_lines;
139 int n_vlines;
140 int n_hlines;
141 gint shift1;
142 gint shift2;
143 sparrow_intersect_t *map;
144 sparrow_corner_t *mesh_mem;
145 sparrow_corner_t *mesh;
146 sparrow_corner_t *mesh_next;
147 sparrow_cluster_t *clusters;
148 double *dither;
149 IplImage *debug;
150 IplImage *threshold;
151 IplImage *working;
152 IplImage *input;
153 edges_state_t state;
154 } sparrow_find_lines_t;
157 #define DEBUG_FIND_LINES(fl)GST_DEBUG( \
158 "fl:\n" \
159 " sparrow_line_t *h_lines: %p\n" \
160 " sparrow_line_t *v_lines: %p\n" \
161 " sparrow_line_t **shuffled_lines: %p\n" \
162 " int current: %d\n" \
163 " int n_lines: %d\n" \
164 " int n_vlines: %d\n" \
165 " int n_hlines: %d\n" \
166 " gint shift1: %d\n" \
167 " gint shift2: %d\n" \
168 " sparrow_intersect_t *map: %p\n" \
169 " sparrow_corner_t *mesh: %p\n" \
170 " sparrow_cluster_t *clusters: %p\n" \
171 " double *dither: %p \n" \
172 " IplImage *debug: %p\n" \
173 " IplImage *threshold: %p\n" \
174 " IplImage *working: %p\n" \
175 " IplImage *input: %p\n" \
176 " edges_state_t state: %d\n" \
178 (fl)->h_lines, \
179 (fl)->v_lines, \
180 (fl)->shuffled_lines, \
181 (fl)->current, \
182 (fl)->n_lines, \
183 (fl)->n_vlines, \
184 (fl)->n_hlines, \
185 (fl)->shift1, \
186 (fl)->shift2, \
187 (fl)->map, \
188 (fl)->mesh, \
189 (fl)->clusters, \
190 (fl)->dither, \
191 (fl)->debug, \
192 (fl)->threshold, \
193 (fl)->working, \
194 (fl)->input, \
195 (fl)->state \
197 //#undef debug_find_lines
198 //#define debug_find_lines(x) /* */
201 #endif /*have this .h*/