Skip to content
Snippets Groups Projects
Commit 236615cc authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Implement retainBest() to get exactly the best N points...

Code copied from https://stackoverflow.com/questions/29085594/cvkeypointsfilterretainbest-isnt-working-as-intended
parent 2237ac90
No related branches found
No related tags found
2 merge requests!36After cmake and const refactor,!28Resolve "Building a new visual odometry system"
......@@ -244,8 +244,10 @@ class ProcessorVisualOdometry : public ProcessorTracker
const TrackMatrix& getTrackMatrix() const {return track_matrix_;}
};
private:
void retainBest(std::vector<cv::KeyPoint> &_keypoints, int n);
};
} //namespace wolf
......
......@@ -634,7 +634,18 @@ bool ProcessorVisualOdometry::filterWithEssential(const KeyPointsMap _mwkps_prev
return true;
}
VisualOdometry::retainBest(std::vector<cv::KeyPoint> &_keypoints, int n)
{
if (_keypoints.size() > n) {
if (n == 0) {
_keypoints.clear();
return;
}
std::nth_element(_keypoints.begin(), _keypoints.begin() + n, _keypoints.end(),
[](cv::KeyPoint& a, cv::KeyPoint& b) { return a.response > b.response; });
_keypoints.resize(n);
}
}
} //namespace wolf
// Register in the FactoryProcessor
......
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