26 #include <utils/math/angle.h> 28 #include <fvmodels/shape/rht_lines.h> 33 #define TEST_IF_IS_A_PIXEL(x) ((x)>230) 45 RhtLinesModel::RhtLinesModel(
float max_time,
int max_iter,
unsigned int nr_candidates,
float angle_from,
float angle_range,
int r_scale,
float min_votes_ratio,
int min_votes)
47 RHT_MAX_TIME = max_time;
48 RHT_MAX_ITER = max_iter;
50 RHT_NR_CANDIDATES = nr_candidates;
52 RHT_R_SCALE = r_scale;
54 RHT_MIN_VOTES = min_votes;
55 RHT_MIN_VOTES_RATIO = min_votes_ratio;
57 RHT_ANGLE_FROM = angle_from - (floor(angle_from / (2 * M_PI )) * (2 * M_PI));
58 RHT_ANGLE_RANGE = angle_range - (floor(angle_range / (2 * M_PI )) * (2 * M_PI));
59 RHT_ANGLE_INCREMENT = RHT_ANGLE_RANGE / RHT_NR_CANDIDATES;
64 RhtLinesModel::~RhtLinesModel(
void)
73 RhtLinesModel::parseImage(
unsigned char *buf,
78 struct timeval start, now;
88 unsigned char *line_start = buffer;
90 vector<point_t> pixels;
92 gettimeofday(&start, NULL);
94 for (y = 0; y < roi->
height; ++y) {
95 for (x = 0; x < roi->
width; ++x) {
96 if (TEST_IF_IS_A_PIXEL(*buffer)) {
110 vector< point_t >::iterator pos;
112 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),
138 gettimeofday(&now, NULL);
140 diff_sec = now.tv_sec - start.tv_sec;
141 diff_usec = now.tv_usec - start.tv_usec;
144 diff_usec += 1000000;
147 f_diff_sec = diff_sec + diff_usec / 1000000.f;
150 }
while( ( ++num_iter < RHT_MAX_ITER) &&
151 ( f_diff_sec < RHT_MAX_TIME) );
154 int max, r_max, phi_max, any_max;
155 max = accumulator.getMax(r_max, phi_max, any_max);
157 roi_width = roi->
width;
161 l.r = r_max * RHT_R_SCALE;
164 m_Lines.push_back( l );
171 RhtLinesModel::getShapeCount(
void)
const 173 return m_Lines.size();
177 RhtLinesModel::getShape(
int id)
const 179 if (
id < 0 || (
unsigned int)
id >= m_Lines.size()) {
182 return const_cast<LineShape*
>(&m_Lines[id]);
188 RhtLinesModel::getMostLikelyShape(
void)
const 190 if (m_Lines.size() == 0) {
192 }
else if (m_Lines.size() == 1) {
193 return const_cast<LineShape*
>(&m_Lines[0]);
196 for (
unsigned int i=1; i < m_Lines.size(); ++i) {
197 if (m_Lines[i].count > m_Lines[cur].count) {
201 return const_cast<LineShape*
>(&m_Lines[cur]);
209 vector< LineShape > *
210 RhtLinesModel::getShapes()
212 int votes = (int)(accumulator.getNumVotes() * (float)RHT_MIN_VOTES_RATIO);
214 if ( RHT_MIN_VOTES > votes ) {
215 votes = RHT_MIN_VOTES;
218 vector< LineShape > * rv =
new vector< LineShape >();
220 vector< vector< int > > *rht_nodes = accumulator.getNodes( votes );
221 vector< vector< int > >::iterator node_it;
225 for (node_it = rht_nodes->begin(); node_it != rht_nodes->end(); ++node_it) {
226 l.r = node_it->at(0) * RHT_R_SCALE;
227 l.phi = node_it->at(1);
229 l.count = node_it->at(3);
Fawkes library namespace.
unsigned int x
x coordinate
unsigned int width
ROI width.
unsigned char * get_roi_buffer_start(unsigned char *buffer) const
Get ROI buffer start.
Point with cartesian coordinates as unsigned integers.
unsigned int y
y coordinate
void calcPoints()
Calc points for line.
float rad2deg(float rad)
Convert an angle given in radians to degrees.
unsigned int height
ROI height.
unsigned int line_step
line step