26 #include <fvmodels/shape/ht_lines.h>
28 #include <utils/math/angle.h>
35 namespace firevision {
37 #define TEST_IF_IS_A_PIXEL(x) ((x) > 230)
60 HtLinesModel::HtLinesModel(
unsigned int nr_candidates,
64 float min_votes_ratio,
67 RHT_NR_CANDIDATES = nr_candidates;
69 RHT_R_SCALE = r_scale;
71 RHT_MIN_VOTES = min_votes;
72 RHT_MIN_VOTES_RATIO = min_votes_ratio;
74 RHT_ANGLE_FROM = angle_from - (floor(angle_from / (2 * M_PI)) * (2 * M_PI));
75 RHT_ANGLE_RANGE = angle_range - (floor(angle_range / (2 * M_PI)) * (2 * M_PI));
76 RHT_ANGLE_INCREMENT = RHT_ANGLE_RANGE / RHT_NR_CANDIDATES;
80 HtLinesModel::~HtLinesModel(
void)
86 HtLinesModel::parseImage(
unsigned char *buf,
ROI *roi)
98 unsigned char * line_start = buffer;
100 vector<upoint_t> pixels;
102 for (y = 0; y < roi->
height; ++y) {
103 for (x = 0; x < roi->
width; ++x) {
104 if (TEST_IF_IS_A_PIXEL(*buffer)) {
106 pixels.push_back(pt);
118 vector<upoint_t>::iterator pos;
119 if (pixels.size() == 0) {
124 while (pixels.size() > 0) {
128 for (
unsigned int i = 0; i < RHT_NR_CANDIDATES; ++i) {
129 phi = RHT_ANGLE_FROM + i * RHT_ANGLE_INCREMENT;
130 r = p.
x * cos(phi) + p.
y * sin(phi);
134 accumulator.accumulate((
int)round(r / RHT_R_SCALE), angle, 0);
139 int max, r_max, phi_max, any_max;
140 max = accumulator.getMax(r_max, phi_max, any_max);
142 roi_width = roi->
width;
146 l.r = r_max * RHT_R_SCALE;
149 m_Lines.push_back(l);
155 HtLinesModel::getShapeCount(
void)
const
157 return m_Lines.size();
161 HtLinesModel::getShape(
int id)
const
163 if (
id < 0 || (
unsigned int)
id >= m_Lines.size()) {
166 return const_cast<LineShape *
>(&m_Lines[id]);
171 HtLinesModel::getMostLikelyShape(
void)
const
173 if (m_Lines.size() == 0) {
175 }
else if (m_Lines.size() == 1) {
176 return const_cast<LineShape *
>(&m_Lines[0]);
179 for (
unsigned int i = 1; i < m_Lines.size(); ++i) {
180 if (m_Lines[i].count > m_Lines[cur].count) {
184 return const_cast<LineShape *
>(&m_Lines[cur]);
192 HtLinesModel::getShapes()
194 int votes = (int)(accumulator.getNumVotes() * (float)RHT_MIN_VOTES_RATIO);
196 if (RHT_MIN_VOTES > votes) {
197 votes = RHT_MIN_VOTES;
200 vector<LineShape> *rv =
new vector<LineShape>();
202 vector<vector<int>> * rht_nodes = accumulator.getNodes(votes);
203 vector<vector<int>>::iterator node_it;
207 for (node_it = rht_nodes->begin(); node_it != rht_nodes->end(); ++node_it) {
208 l.r = node_it->at(0) * RHT_R_SCALE;
209 l.phi = node_it->at(1);
211 l.count = node_it->at(3);
void calcPoints()
Calc points for line.
unsigned int height
ROI height.
unsigned char * get_roi_buffer_start(unsigned char *buffer) const
Get ROI buffer start.
unsigned int line_step
line step
unsigned int width
ROI width.
Fawkes library namespace.
float rad2deg(float rad)
Convert an angle given in radians to degrees.
Point with cartesian coordinates as unsigned integers.
unsigned int x
x coordinate
unsigned int y
y coordinate