Skip to content
Snippets Groups Projects
Commit 8cf2bf52 authored by jvallve's avatar jvallve
Browse files

detecció linies amb window size variable

parent 66b2f706
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,8 @@ int main(int argc, char** argv) ...@@ -95,7 +95,8 @@ int main(int argc, char** argv)
laserscanutils::ExtractCornerParams alg_params; laserscanutils::ExtractCornerParams alg_params;
alg_params.line_params_.jump_dist_ut_ = 1.0; alg_params.line_params_.jump_dist_ut_ = 1.0;
alg_params.line_params_.window_sz_ = 6; alg_params.line_params_.window_sz_ = 0.5;
alg_params.line_params_.min_window_points_ = 5;
alg_params.line_params_.k_sigmas_ut_ = 3; alg_params.line_params_.k_sigmas_ut_ = 3;
alg_params.line_params_.concatenate_ii_ut_ = 5; alg_params.line_params_.concatenate_ii_ut_ = 5;
alg_params.line_params_.concatenate_angle_ut_ = 0.1; alg_params.line_params_.concatenate_angle_ut_ = 0.1;
......
...@@ -35,52 +35,60 @@ unsigned int laserscanutils::extractLines(const laserscanutils::ScanParams & _pa ...@@ -35,52 +35,60 @@ unsigned int laserscanutils::extractLines(const laserscanutils::ScanParams & _pa
Line line; Line line;
std::list<Line>::iterator line_it1, line_it2; std::list<Line>::iterator line_it1, line_it2;
std::list<unsigned int> jumps; std::list<unsigned int> jumps;
std::vector<float> ranges = _ranges;
std::list<unsigned int>::iterator jj_jump; std::list<unsigned int>::iterator jj_jump;
bool update_iterators; bool update_iterators;
unsigned int ii1,ii2; unsigned int ii, window_points;
//STEP 1: transform to euclidean coordinates and detect jumps //STEP 1: transform to euclidean coordinates and detect jumps
ranges2xy(_params, _ranges, _alg_params.jump_dist_ut_, points, jumps); ranges2xy(_params, ranges, _alg_params.jump_dist_ut_, points, jumps);
// std::cout << "jumps: " << jumps.size() << std::endl; // std::cout << "jumps: " << jumps.size() << std::endl;
// std::cout << "points: " << points.rows() << "x" << points.cols()<< std::endl; // std::cout << "points: " << points.rows() << "x" << points.cols()<< std::endl;
// STEP 2: find line segments running over the scan // STEP 2: find line segments running over the scan
ii1 = 0; ii = 0;
ii2=_alg_params.window_sz_; //ii2=_alg_params.window_sz_;
window_points = std::max(_alg_params.min_window_points_, (unsigned int)(_alg_params.window_sz_ / (_params.angle_step_ * ranges[ii])));
jj_jump = jumps.begin(); jj_jump = jumps.begin();
while ( ii2 < points.cols() )
while ( ii+window_points < points.cols() )
{ {
//check if a jump exists between ii1 and ii2 //check if a jump exists between ii and ii+window_points
if ( jj_jump != jumps.end() ) if ( jj_jump != jumps.end() && ii < (*jj_jump) && (ii+window_points >= (*jj_jump)) )
{
ii = *jj_jump;
jj_jump++;
}
else
{ {
if (ii1 < (*jj_jump) && (ii2 >= (*jj_jump)) ) //Found the best fitting line over points within the window [ii,ii+window_points]
fitLine(points.block(0,ii,3,window_points), line);
//if error below stdev, add line to ScalarT cornerAperture(const Eigen::Vector3s & _p1, const Eigen::Vector3s & _c, const Eigen::Vector3s & _p2);result set
if ( line.error_ < _params.range_std_dev_*_alg_params.k_sigmas_ut_ )
{ {
ii1 = *jj_jump; line.first_ = ii;
ii2 = *jj_jump + _alg_params.window_sz_; line.last_ = ii + window_points;
jj_jump++; line.point_first_ = points.col(line.first_);
continue;//move to while loop line.point_last_ = points.col(line.last_);
line.np_ = line.last_ - line.first_ + 1;
_line_list.push_back(line);
} }
}
//Found the best fitting line over points within the window [ii1,ii2]
fitLine(points.block(0,ii1,3,_alg_params.window_sz_), line);
//if error below stdev, add line to ScalarT cornerAperture(const Eigen::Vector3s & _p1, const Eigen::Vector3s & _c, const Eigen::Vector3s & _p2);result set //increment window iterators
if ( line.error_ < _params.range_std_dev_*_alg_params.k_sigmas_ut_ ) ii++;
{
line.first_ = ii1;
line.last_ = ii2;
line.point_first_ = points.col(line.first_);
line.point_last_ = points.col(line.last_);
line.np_ = line.last_ - line.first_ + 1;
_line_list.push_back(line);
} }
window_points = std::max(_alg_params.min_window_points_, (unsigned int)(_alg_params.window_sz_ / (_params.angle_step_ * ranges[ii])));
//increment window iterators std::cout << "min window points: " << _alg_params.min_window_points_ << std::endl;
ii1++; std::cout << "range: " << ranges[ii] << std::endl;
ii2++; std::cout << "l_step: " << _params.angle_step_ * ranges[ii] << std::endl;
std::cout << "window_sz: " << _alg_params.window_sz_ << std::endl;
std::cout << "window size / l_step: " << (_alg_params.window_sz_ / (_params.angle_step_ * ranges[ii])) << std::endl;
std::cout << "(unsigned int) window size / l_step: " << (unsigned int)(_alg_params.window_sz_ / (_params.angle_step_ * ranges[ii])) << std::endl;
std::cout << "window_points: " << window_points << std::endl << std::endl;
} }
// std::cout << "Lines fitted: " << _line_list.size() << std::endl; std::cout << "Lines fitted: " << _line_list.size() << std::endl;
//STEP 3: concatenate lines //STEP 3: concatenate lines
if ( _line_list.size() < 2 ) return _line_list.size(); //In case just less than two lines found, return if ( _line_list.size() < 2 ) return _line_list.size(); //In case just less than two lines found, return
...@@ -134,7 +142,7 @@ unsigned int laserscanutils::extractLines(const laserscanutils::ScanParams & _pa ...@@ -134,7 +142,7 @@ unsigned int laserscanutils::extractLines(const laserscanutils::ScanParams & _pa
line_it2++; line_it2++;
} }
} }
//std::cout << "Lines after concatenation: " << _line_list.size() << std::endl; std::cout << "Lines after concatenation: " << _line_list.size() << std::endl;
return _line_list.size(); return _line_list.size();
} }
......
...@@ -17,8 +17,9 @@ namespace laserscanutils ...@@ -17,8 +17,9 @@ namespace laserscanutils
struct ExtractLineParams struct ExtractLineParams
{ {
//members //members
double jump_dist_ut_; //Upper threshold in consecutive ranges to consider a jump ScalarT jump_dist_ut_; //Upper threshold in consecutive ranges to consider a jump
unsigned int window_sz_; //number of points to fit lines in the first pass ScalarT window_sz_; // size (m) of the window of points to fit lines in the first pass
unsigned int min_window_points_; // minimum number of points to fit lines in the first pass
ScalarT k_sigmas_ut_;//Uppet threshold of how many std_dev are tolerated to count that a point is supporting a line ScalarT k_sigmas_ut_;//Uppet threshold of how many std_dev are tolerated to count that a point is supporting a line
unsigned int concatenate_ii_ut_;//Upper threshold for ray index difference between consecutive lines to consider concatenation unsigned int concatenate_ii_ut_;//Upper threshold for ray index difference between consecutive lines to consider concatenation
ScalarT concatenate_angle_ut_; //Upper threshold for angle between consecutive lines to consider concatenation ScalarT concatenate_angle_ut_; //Upper threshold for angle between consecutive lines to consider concatenation
......
...@@ -12,11 +12,11 @@ void laserscanutils::ScanParams::print() const ...@@ -12,11 +12,11 @@ void laserscanutils::ScanParams::print() const
<< " Range std dev: " << range_std_dev_ << std::endl; << " Range std dev: " << range_std_dev_ << std::endl;
} }
void laserscanutils::ranges2xy(const ScanParams & _params, const std::vector<float> & _ranges, const ScalarT& _jump_threshold, Eigen::MatrixXs & _points, std::list<unsigned int> & _jumps) void laserscanutils::ranges2xy(const ScanParams & _params, std::vector<float> & _ranges, const ScalarT& _jump_threshold, Eigen::MatrixXs & _points, std::list<unsigned int> & _jumps)
{ {
ScalarT azimuth = 0.0; ScalarT azimuth = 0.0;
ScalarT prev_range; ScalarT prev_range;
unsigned int ii, ii_ok; unsigned int ii = 0;
//resize to all points case //resize to all points case
_points.resize(3,_ranges.size()); _points.resize(3,_ranges.size());
...@@ -25,28 +25,30 @@ void laserscanutils::ranges2xy(const ScanParams & _params, const std::vector<flo ...@@ -25,28 +25,30 @@ void laserscanutils::ranges2xy(const ScanParams & _params, const std::vector<flo
_jumps.clear(); _jumps.clear();
//for each range, check correctness of value and translate from polar to xy coordinates //for each range, check correctness of value and translate from polar to xy coordinates
for(ii=0, ii_ok=0; ii<_ranges.size(); ++ii) while (ii <_ranges.size())
{ {
if ( _ranges[ii] >=_params.range_min_ && _ranges[ii] <= _params.range_max_ && !isnan(_ranges[ii]) && !isinf(_ranges[ii]) ) if ( _ranges[ii] >_params.range_min_ && _ranges[ii] < _params.range_max_ && !isnan(_ranges[ii]) && !isinf(_ranges[ii]) )
{ {
//transform from polar to euclidean //transform from polar to euclidean
azimuth = _params.angle_min_+ _params.angle_step_*ii; azimuth = _params.angle_min_+ _params.angle_step_*ii;
_points(0,ii_ok) = _ranges[ii] * cos(azimuth); _points(0,ii) = _ranges[ii] * cos(azimuth);
_points(1,ii_ok) = _ranges[ii] * sin(azimuth); _points(1,ii) = _ranges[ii] * sin(azimuth);
_points(2,ii_ok) = 1; _points(2,ii) = 1;
//check jump //check jump
if ( (ii_ok != 0) && (fabs(_ranges[ii]-prev_range) > _jump_threshold) ) if ( (ii != 0) && (fabs(_ranges[ii]-prev_range) > _jump_threshold) )
_jumps.push_back(ii_ok); _jumps.push_back(ii);
//keep current range and update counter //keep current range and update counter
prev_range = _ranges[ii]; prev_range = _ranges[ii];
ii_ok ++; ii ++;
} }
else
_ranges.erase(_ranges.begin()+ii);
} }
//resize the output matrix to the number of correct points, while keeping values //resize the output matrix to the number of correct points, while keeping values
_points.conservativeResize(3, ii_ok); _points.conservativeResize(3, _ranges.size());
//_points.conservativeResize(Eigen::NoChange_t, ii_ok); //does not compile ... why ? //_points.conservativeResize(Eigen::NoChange_t, ii_ok); //does not compile ... why ?
} }
......
...@@ -33,6 +33,7 @@ namespace laserscanutils ...@@ -33,6 +33,7 @@ namespace laserscanutils
* Transforms from polar (ranges) to euclidean (xy), while checking correctness of raw data. * Transforms from polar (ranges) to euclidean (xy), while checking correctness of raw data.
* Invalid values (inf's and nan's) and out of range measurements are not transformed. * Invalid values (inf's and nan's) and out of range measurements are not transformed.
* Valid measurements are returned, by reference, in homogeneous coordinates. * Valid measurements are returned, by reference, in homogeneous coordinates.
* Ranges vector is returned with all not correct elements removed.
* A list of jumps indices is also returned by reference. * A list of jumps indices is also returned by reference.
* \param _params laser_scan_utils structure of the laser scan parameters. * \param _params laser_scan_utils structure of the laser scan parameters.
* \param _ranges raw range measurements from the laser scanner device. Size Nr. Type float to match ROS LaserScan message * \param _ranges raw range measurements from the laser scanner device. Size Nr. Type float to match ROS LaserScan message
...@@ -41,7 +42,7 @@ namespace laserscanutils ...@@ -41,7 +42,7 @@ namespace laserscanutils
* \param jumps_id_ list of indexes of jumps in range measurements. Indexes correpond to _points vector. * \param jumps_id_ list of indexes of jumps in range measurements. Indexes correpond to _points vector.
* *
**/ **/
void ranges2xy(const ScanParams & _params, const std::vector<float> & _ranges, const ScalarT& _jump_threshold, Eigen::MatrixXs & _points, std::list<unsigned int> & _jumps); void ranges2xy(const ScanParams & _params, std::vector<float> & _ranges, const ScalarT& _jump_threshold, Eigen::MatrixXs & _points, std::list<unsigned int> & _jumps);
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment