26 #include <fvmodels/shape/rht_lines.h> 28 #include <utils/math/angle.h> 33 #define TEST_IF_IS_A_PIXEL(x) ((x) > 230) 35 namespace firevision {
42 RhtLinesModel::RhtLinesModel(
float max_time,
44 unsigned int nr_candidates,
48 float min_votes_ratio,
51 RHT_MAX_TIME = max_time;
52 RHT_MAX_ITER = max_iter;
54 RHT_NR_CANDIDATES = nr_candidates;
56 RHT_R_SCALE = r_scale;
58 RHT_MIN_VOTES = min_votes;
59 RHT_MIN_VOTES_RATIO = min_votes_ratio;
61 RHT_ANGLE_FROM = angle_from - (floor(angle_from / (2 * M_PI)) * (2 * M_PI));
62 RHT_ANGLE_RANGE = angle_range - (floor(angle_range / (2 * M_PI)) * (2 * M_PI));
63 RHT_ANGLE_INCREMENT = RHT_ANGLE_RANGE / RHT_NR_CANDIDATES;
67 RhtLinesModel::~RhtLinesModel(
void)
76 RhtLinesModel::parseImage(
unsigned char *buf,
ROI *roi)
80 struct timeval start, now;
90 unsigned char * line_start = buffer;
92 vector<upoint_t> pixels;
94 gettimeofday(&start, NULL);
96 for (y = 0; y < roi->
height; ++y) {
97 for (x = 0; x < roi->
width; ++x) {
98 if (TEST_IF_IS_A_PIXEL(*buffer)) {
100 pixels.push_back(pt);
112 vector<upoint_t>::iterator pos;
114 if (pixels.size() == 0) {
121 if (pixels.size() > 0) {
122 int ri = rand() % pixels.size();
123 pos = pixels.begin() + ri;
127 for (
unsigned int i = 0; i < RHT_NR_CANDIDATES; ++i) {
128 phi = RHT_ANGLE_FROM + i * RHT_ANGLE_INCREMENT;
129 r = p.
x * cos(phi) + p.
y * sin(phi);
133 accumulator.accumulate((
int)round(r / RHT_R_SCALE), angle, 0);
136 gettimeofday(&now, NULL);
138 diff_sec = now.tv_sec - start.tv_sec;
139 diff_usec = now.tv_usec - start.tv_usec;
142 diff_usec += 1000000;
145 f_diff_sec = diff_sec + diff_usec / 1000000.f;
148 }
while ((++num_iter < RHT_MAX_ITER) && (f_diff_sec < RHT_MAX_TIME));
151 int max, r_max, phi_max, any_max;
152 max = accumulator.getMax(r_max, phi_max, any_max);
154 roi_width = roi->
width;
158 l.r = r_max * RHT_R_SCALE;
161 m_Lines.push_back(l);
167 RhtLinesModel::getShapeCount(
void)
const 169 return m_Lines.size();
173 RhtLinesModel::getShape(
int id)
const 175 if (
id < 0 || (
unsigned int)
id >= m_Lines.size()) {
178 return const_cast<LineShape *>(&m_Lines[
id]);
183 RhtLinesModel::getMostLikelyShape(
void)
const 185 if (m_Lines.size() == 0) {
187 }
else if (m_Lines.size() == 1) {
188 return const_cast<LineShape *>(&m_Lines[0]);
191 for (
unsigned int i = 1; i < m_Lines.size(); ++i) {
192 if (m_Lines[i].count > m_Lines[cur].count) {
196 return const_cast<LineShape *>(&m_Lines[cur]);
204 RhtLinesModel::getShapes()
206 int votes = (int)(accumulator.getNumVotes() * (float)RHT_MIN_VOTES_RATIO);
208 if (RHT_MIN_VOTES > votes) {
209 votes = RHT_MIN_VOTES;
212 vector<LineShape> *rv =
new vector<LineShape>();
214 vector<vector<int>> * rht_nodes = accumulator.getNodes(votes);
215 vector<vector<int>>::iterator node_it;
219 for (node_it = rht_nodes->begin(); node_it != rht_nodes->end(); ++node_it) {
220 l.r = node_it->at(0) * RHT_R_SCALE;
221 l.phi = node_it->at(1);
223 l.count = node_it->at(3);
Fawkes library namespace.
unsigned int y
y coordinate
unsigned int x
x coordinate
unsigned int width
ROI width.
void calcPoints()
Calc points for line.
unsigned char * get_roi_buffer_start(unsigned char *buffer) const
Get ROI buffer start.
Point with cartesian coordinates as unsigned integers.
float rad2deg(float rad)
Convert an angle given in radians to degrees.
unsigned int height
ROI height.
unsigned int line_step
line step