clamped difference projection
[sparrow.git] / edges.h
blob03278bf167470a656a61caccadc4d4f46ec10b2a
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 sparrow_intersect_t *map;
143 sparrow_corner_t *mesh_mem;
144 sparrow_corner_t *mesh;
145 sparrow_corner_t *mesh_next;
146 sparrow_cluster_t *clusters;
147 double *dither;
148 IplImage *debug;
149 IplImage *threshold;
150 IplImage *working;
151 IplImage *input;
152 edges_state_t state;
153 } sparrow_find_lines_t;
156 #define DEBUG_FIND_LINES(fl)GST_DEBUG( \
157 "fl:\n" \
158 " sparrow_line_t *h_lines: %p\n" \
159 " sparrow_line_t *v_lines: %p\n" \
160 " sparrow_line_t **shuffled_lines: %p\n" \
161 " int current: %d\n" \
162 " int n_lines: %d\n" \
163 " int n_vlines: %d\n" \
164 " int n_hlines: %d\n" \
165 " gint shift1: %d\n" \
166 " gint shift2: %d\n" \
167 " sparrow_intersect_t *map: %p\n" \
168 " sparrow_corner_t *mesh: %p\n" \
169 " sparrow_cluster_t *clusters: %p\n" \
170 " double *dither: %p \n" \
171 " IplImage *debug: %p\n" \
172 " IplImage *threshold: %p\n" \
173 " IplImage *working: %p\n" \
174 " IplImage *input: %p\n" \
175 " edges_state_t state: %d\n" \
177 (fl)->h_lines, \
178 (fl)->v_lines, \
179 (fl)->shuffled_lines, \
180 (fl)->current, \
181 (fl)->n_lines, \
182 (fl)->n_vlines, \
183 (fl)->n_hlines, \
184 (fl)->shift1, \
185 (fl)->shift2, \
186 (fl)->map, \
187 (fl)->mesh, \
188 (fl)->clusters, \
189 (fl)->dither, \
190 (fl)->debug, \
191 (fl)->threshold, \
192 (fl)->working, \
193 (fl)->input, \
194 (fl)->state \
196 //#undef debug_find_lines
197 //#define debug_find_lines(x) /* */
200 #endif /*have this .h*/