try to compensate for bad signal from other side: doesn't work\!
[sparrow.git] / edges.h
blob3c1f94330867b254a0c24aa617c0057c97800c14
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_FIND_LINES,
45 EDGES_FIND_CORNERS,
46 EDGES_WAIT_FOR_PLAY,
48 EDGES_NEXT_STATE,
49 } edges_state_t;
51 #define USE_FLOAT_COORDS 1
53 #if USE_FLOAT_COORDS
54 typedef float coord_t;
55 typedef float coord_sum_t;
56 #define QUANTISE_DELTA(d)((d) / LINE_PERIOD)
58 #else
59 /* the mesh is stored in a fixed point notation.*/
60 #define SPARROW_FIXED_POINT 9
62 typedef int coord_t;
63 typedef gint64 coord_sum_t;
64 #define QUANTISE_DELTA(d)(((d) + LINE_PERIOD / 2) / LINE_PERIOD)
66 #endif
68 typedef struct sparrow_estimator_s {
69 int x1;
70 int y1;
71 int x2;
72 int y2;
73 int x3;
74 int y3;
75 //int mul; /* estimate: x1,y1 + mul * diff */
76 } sparrow_estimator_t;
78 typedef struct sparrow_corner_s {
79 coord_t x;
80 coord_t y;
81 /*dyr -> dy to next point right
82 dxd ->dx to next point down */
83 coord_t dxr;
84 coord_t dyr;
85 coord_t dxd;
86 coord_t dyd;
87 corner_status_t status;
88 } sparrow_corner_t;
90 typedef struct sparrow_voter_s {
91 coord_t x;
92 coord_t y;
93 guint32 signal;
94 } sparrow_voter_t;
96 typedef struct sparrow_point_s {
97 coord_t x;
98 coord_t y;
99 } sparrow_point_t;
101 typedef struct sparrow_cluster_s {
102 int n;
103 sparrow_voter_t voters[8];
104 } sparrow_cluster_t;
107 typedef union sparrow_signal_s {
108 guint16 v_signal;
109 guint16 h_signal;
110 } sparrow_signal_t;
113 typedef struct sparrow_intersect_s {
114 guint16 lines[2];
115 guint16 signal[2];
116 } sparrow_intersect_t;
118 typedef struct sparrow_line_s {
119 gint offset;
120 sparrow_axis_t dir;
121 gint index;
122 } sparrow_line_t;
124 /*condensed version of <struct sparrow_find_lines_s> for saving: contains no
125 pointers or other unnecessary things that might vary in size across
126 architectures. */
127 typedef struct sparrow_fl_condensed {
128 gint32 n_vlines;
129 gint32 n_hlines;
130 } sparrow_fl_condensed_t;
132 typedef struct sparrow_find_lines_s {
133 sparrow_line_t *h_lines;
134 sparrow_line_t *v_lines;
135 sparrow_line_t **shuffled_lines;
136 int current;
137 int n_lines;
138 int n_vlines;
139 int n_hlines;
140 gint shift1;
141 gint shift2;
142 gint unshift1;
143 gint unshift2;
144 sparrow_intersect_t *map;
145 sparrow_corner_t *mesh_mem;
146 sparrow_corner_t *mesh;
147 sparrow_corner_t *mesh_next;
148 sparrow_cluster_t *clusters;
149 double *dither;
150 IplImage *debug;
151 IplImage *threshold;
152 IplImage *working;
153 IplImage *input;
154 edges_state_t state;
155 } sparrow_find_lines_t;
158 #define DEBUG_FIND_LINES(fl)GST_DEBUG( \
159 "fl:\n" \
160 " sparrow_line_t *h_lines: %p\n" \
161 " sparrow_line_t *v_lines: %p\n" \
162 " sparrow_line_t **shuffled_lines: %p\n" \
163 " int current: %d\n" \
164 " int n_lines: %d\n" \
165 " int n_vlines: %d\n" \
166 " int n_hlines: %d\n" \
167 " gint shift1: %d\n" \
168 " gint shift2: %d\n" \
169 " gint unshift1: %d\n" \
170 " gint unshift2: %d\n" \
171 " sparrow_intersect_t *map: %p\n" \
172 " sparrow_corner_t *mesh: %p\n" \
173 " sparrow_cluster_t *clusters: %p\n" \
174 " double *dither: %p \n" \
175 " IplImage *debug: %p\n" \
176 " IplImage *threshold: %p\n" \
177 " IplImage *working: %p\n" \
178 " IplImage *input: %p\n" \
179 " edges_state_t state: %d\n" \
181 (fl)->h_lines, \
182 (fl)->v_lines, \
183 (fl)->shuffled_lines, \
184 (fl)->current, \
185 (fl)->n_lines, \
186 (fl)->n_vlines, \
187 (fl)->n_hlines, \
188 (fl)->shift1, \
189 (fl)->shift2, \
190 (fl)->unshift1, \
191 (fl)->unshift2, \
192 (fl)->map, \
193 (fl)->mesh, \
194 (fl)->clusters, \
195 (fl)->dither, \
196 (fl)->debug, \
197 (fl)->threshold, \
198 (fl)->working, \
199 (fl)->input, \
200 (fl)->state \
202 //#undef debug_find_lines
203 //#define debug_find_lines(x) /* */
206 #endif /*have this .h*/