24 #include <core/exceptions/software.h>
31 namespace firevision {
51 GradientClassifier::GradientClassifier(std::list<ScanlineGrid* >* scanlines,
53 unsigned int threshold,
unsigned int max_size,
54 bool use_rising_flank,
bool use_falling_flank)
62 _scanlines = scanlines;
67 set_edges(use_rising_flank, use_falling_flank);
85 _threshold = threshold;
100 _use_rising_edge = use_rising_edge;
101 _use_falling_edge = use_falling_edge;
113 unsigned int width,
unsigned int height)
126 return new std::list< ROI >;
129 list< ROI > *rv =
new list< ROI >;
130 int cur_val, cur_diff, direction = 0;
132 cur_pos.
x = cur_pos.
y = edge_start.
x = edge_start.
y = 0;
134 unsigned int jumpSize = 0;
138 for (list<ScanlineGrid*>::iterator it = _scanlines->begin(); it != _scanlines->end(); it++)
144 _last_val = _q->
get(_last_pos);
146 while(!slm->finished())
148 cur_pos = *(++(*slm));
149 cur_val = _q->
get(cur_pos);
150 cur_diff = cur_val - _last_val;
152 if ((cur_pos.
x < _last_pos.
x || cur_pos.
y < _last_pos.
y)
154 || (cur_pos.
y - current.
start.
y) > _max_size)))
158 edge_start.
x = edge_start.
y = direction = jumpSize = 0;
161 int curDir = (cur_diff < 0 ? -1 : (cur_diff > 0 ? 1 : 0));
168 jumpSize -= cur_diff;
171 jumpSize = -cur_diff;
172 edge_start = cur_pos;
175 if (jumpSize < _threshold)
177 jumpSize = -cur_diff;
178 edge_start = cur_pos;
187 rv->push_back(
ROI(current));
191 else if (_use_falling_edge)
197 edge_start = cur_pos;
198 jumpSize = -cur_diff;
211 if (jumpSize >= _threshold)
218 rv->push_back(
ROI(current));
224 if ((_use_falling_edge && direction == 1) || (_use_rising_edge && direction == -1))
236 direction = jumpSize = 0;
237 edge_start.
x = edge_start.
y = 0;
245 jumpSize += cur_diff;
249 edge_start = cur_pos;
252 if (jumpSize < _threshold)
255 edge_start = cur_pos;
264 rv->push_back(
ROI(current));
268 else if (_use_rising_edge)
274 edge_start = cur_pos;