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) 51 HtLinesModel::HtLinesModel(
unsigned int nr_candidates,
55 float min_votes_ratio,
58 RHT_NR_CANDIDATES = nr_candidates;
60 RHT_R_SCALE = r_scale;
62 RHT_MIN_VOTES = min_votes;
63 RHT_MIN_VOTES_RATIO = min_votes_ratio;
65 RHT_ANGLE_FROM = angle_from - (floor(angle_from / (2 * M_PI)) * (2 * M_PI));
66 RHT_ANGLE_RANGE = angle_range - (floor(angle_range / (2 * M_PI)) * (2 * M_PI));
67 RHT_ANGLE_INCREMENT = RHT_ANGLE_RANGE / RHT_NR_CANDIDATES;
71 HtLinesModel::~HtLinesModel(
void)
77 HtLinesModel::parseImage(
unsigned char *buf,
ROI *roi)
89 unsigned char * line_start = buffer;
91 vector<upoint_t> pixels;
93 for (y = 0; y < roi->
height; ++y) {
94 for (x = 0; x < roi->
width; ++x) {
95 if (TEST_IF_IS_A_PIXEL(*buffer)) {
109 vector<upoint_t>::iterator pos;
110 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), angle, 0);
130 int max, r_max, phi_max, any_max;
131 max = accumulator.getMax(r_max, phi_max, any_max);
133 roi_width = roi->
width;
137 l.r = r_max * RHT_R_SCALE;
140 m_Lines.push_back(l);
146 HtLinesModel::getShapeCount(
void)
const 148 return m_Lines.size();
152 HtLinesModel::getShape(
int id)
const 154 if (
id < 0 || (
unsigned int)
id >= m_Lines.size()) {
157 return const_cast<LineShape *>(&m_Lines[
id]);
162 HtLinesModel::getMostLikelyShape(
void)
const 164 if (m_Lines.size() == 0) {
166 }
else if (m_Lines.size() == 1) {
167 return const_cast<LineShape *>(&m_Lines[0]);
170 for (
unsigned int i = 1; i < m_Lines.size(); ++i) {
171 if (m_Lines[i].count > m_Lines[cur].count) {
175 return const_cast<LineShape *>(&m_Lines[cur]);
183 HtLinesModel::getShapes()
185 int votes = (int)(accumulator.getNumVotes() * (float)RHT_MIN_VOTES_RATIO);
187 if (RHT_MIN_VOTES > votes) {
188 votes = RHT_MIN_VOTES;
191 vector<LineShape> *rv =
new vector<LineShape>();
193 vector<vector<int>> * rht_nodes = accumulator.getNodes(votes);
194 vector<vector<int>>::iterator node_it;
198 for (node_it = rht_nodes->begin(); node_it != rht_nodes->end(); ++node_it) {
199 l.r = node_it->at(0) * RHT_R_SCALE;
200 l.phi = node_it->at(1);
202 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