Skip to content
Snippets Groups Projects
Commit 3c038736 authored by Andreu Corominas-Murtra's avatar Andreu Corominas-Murtra
Browse files

Improved performance of Hough line fineder by a actor of 2.5. Sparse matrix...

Improved performance of Hough line fineder by a actor of 2.5. Sparse matrix filled through Triplet's.
parent 9681e4e4
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,7 @@ unsigned int LineFinderHough::findLines( const Eigen::MatrixXs & _points,
Eigen::SparseMatrix<unsigned int> sum_grid(hough_grid_rows,hough_grid_cols);
std::list<Eigen::SparseMatrix<unsigned int> >::iterator subgrid_it;
Eigen::MatrixXs support_points;
std::vector<Eigen::Triplet<unsigned int> > triplet_vector;
//clear the Houhg Grid
// for (unsigned int ii = 0; ii < hough_grid_.size(); ii++)
......@@ -62,6 +63,12 @@ unsigned int LineFinderHough::findLines( const Eigen::MatrixXs & _points,
//push_back a new Sparse Matrix to hough_grid_. Each SparseMatrix represents the grid for one point.
hough_grid_x_.push_back(Eigen::SparseMatrix<unsigned int>(hough_grid_rows,hough_grid_cols));
//clear the triplet_vector
triplet_vector.clear();
//reserve space for triplet vector
triplet_vector.reserve(hough_grid_rows*2);
//loop over all theta values in the grid
for (unsigned int jth = 0; jth < hough_grid_rows; jth++)
{
......@@ -79,9 +86,11 @@ unsigned int LineFinderHough::findLines( const Eigen::MatrixXs & _points,
//hough_grid_.at(jth).at(kr).push_back( Eigen::Vector3s(_points(0,ipt),_points(1,ipt),1 ));
//Anotate the support of point ipt to cell (jth,kr)
hough_grid_x_.back().coeffRef(jth,kr) = 1;
//hough_grid_x_.back().coeffRef(jth,kr) = 1;
triplet_vector.push_back(Eigen::Triplet<unsigned int>(jth,kr,1));
}
}
hough_grid_x_.back().setFromTriplets(triplet_vector.begin(), triplet_vector.end());
}
////STEP 2 .Find cells having a peak of at least min_supports_ points supporting them
......@@ -94,20 +103,20 @@ unsigned int LineFinderHough::findLines( const Eigen::MatrixXs & _points,
sum_grid = sum_grid + (*subgrid_it);
}
//Find the max_value at sum_grid -> r,th TODO: improve it by exploiting sparsity (not running over all matrix!)
//Find the max_value at sum_grid -> r,th . Run over the Sparse Matrix sum_grid
max_value = 0;
for (unsigned int ii = 0; ii < hough_grid_rows; ii++)
for (int ii=0; ii<sum_grid.outerSize(); ii++)
{
for (unsigned int jj = 0; jj < hough_grid_cols; jj++)
for (Eigen::SparseMatrix<unsigned int>::InnerIterator it(sum_grid,ii); it; ++it)
{
if ( sum_grid.coeffRef(ii,jj) > max_value )
if ( it.value() > max_value )
{
max_value = sum_grid.coeffRef(ii,jj);
ii_max_value = ii;
jj_max_value = jj;
max_value = it.value();
ii_max_value = it.row();
jj_max_value = it.col();
}
}
}
}
//max_value is the number of supporters for the most supported cell. Ceck if it has enough supporters
if ( max_value < hough_params_.min_supports_ )
......@@ -180,7 +189,7 @@ unsigned int LineFinderHough::findLines( const Eigen::MatrixXs & _points,
//push back the line to the list
_line_list.push_back(line);
}
}
}//closes while
// for (unsigned int ii = 1; ii < hough_grid_rows-1; ii++)
// {
......
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