28 #include <fvmodels/shape/ht_lines.h> 29 #include <utils/math/angle.h> 39 #define TEST_IF_IS_A_PIXEL(x) ((x)>230) 53 HtLinesModel::HtLinesModel(
unsigned int nr_candidates,
float angle_from,
float angle_range,
int r_scale,
float min_votes_ratio,
int min_votes)
55 RHT_NR_CANDIDATES = nr_candidates;
57 RHT_R_SCALE = r_scale;
59 RHT_MIN_VOTES = min_votes;
60 RHT_MIN_VOTES_RATIO = min_votes_ratio;
62 RHT_ANGLE_FROM = angle_from - (floor(angle_from / (2 * M_PI )) * (2 * M_PI));
63 RHT_ANGLE_RANGE = angle_range - (floor(angle_range / (2 * M_PI )) * (2 * M_PI));
64 RHT_ANGLE_INCREMENT = RHT_ANGLE_RANGE / RHT_NR_CANDIDATES;
69 HtLinesModel::~HtLinesModel(
void)
75 HtLinesModel::parseImage(
unsigned char *buf,
88 unsigned char *line_start = buffer;
90 vector<upoint_t> pixels;
92 for (y = 0; y < roi->
height; ++y) {
93 for (x = 0; x < roi->
width; ++x) {
94 if (TEST_IF_IS_A_PIXEL(*buffer)) {
108 vector< upoint_t >::iterator pos;
109 if (pixels.size() == 0) {
115 while (pixels.size() > 0) {
119 for (
unsigned int i = 0; i < RHT_NR_CANDIDATES; ++i) {
120 phi = RHT_ANGLE_FROM + i * RHT_ANGLE_INCREMENT;
121 r = p.
x * cos( phi ) + p.
y * sin( phi );
125 accumulator.accumulate( (
int)round(r / RHT_R_SCALE),
133 int max, r_max, phi_max, any_max;
134 max = accumulator.getMax(r_max, phi_max, any_max);
136 roi_width = roi->
width;
140 l.r = r_max * RHT_R_SCALE;
143 m_Lines.push_back( l );
150 HtLinesModel::getShapeCount(
void)
const 152 return m_Lines.size();
156 HtLinesModel::getShape(
int id)
const 158 if (
id < 0 || (
unsigned int)
id >= m_Lines.size()) {
161 return const_cast<LineShape*
>(&m_Lines[id]);
167 HtLinesModel::getMostLikelyShape(
void)
const 169 if (m_Lines.size() == 0) {
171 }
else if (m_Lines.size() == 1) {
172 return const_cast<LineShape*
>(&m_Lines[0]);
175 for (
unsigned int i=1; i < m_Lines.size(); ++i) {
176 if (m_Lines[i].count > m_Lines[cur].count) {
180 return const_cast<LineShape*
>(&m_Lines[cur]);
188 vector< LineShape > *
189 HtLinesModel::getShapes()
191 int votes = (int)(accumulator.getNumVotes() * (float)RHT_MIN_VOTES_RATIO);
193 if ( RHT_MIN_VOTES > votes ) {
194 votes = RHT_MIN_VOTES;
197 vector< LineShape > * rv =
new vector< LineShape >();
199 vector< vector< int > > *rht_nodes = accumulator.getNodes( votes );
200 vector< vector< int > >::iterator node_it;
204 for (node_it = rht_nodes->begin(); node_it != rht_nodes->end(); ++node_it) {
205 l.r = node_it->at(0) * RHT_R_SCALE;
206 l.phi = node_it->at(1);
208 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