Commit 97640847 authored by Andrey Kamaev's avatar Andrey Kamaev

Add methods to sort keypoints and corresponding descriptors

parent 18295bc7
......@@ -27,6 +27,7 @@ PERF_TEST_P(orb, detect, testing::Values(ORB_IMAGES))
TEST_CYCLE() detector(frame, mask, points);
sort(points.begin(), points.end(), comparators::KeypointGreater());
SANITY_CHECK_KEYPOINTS(points);
}
......@@ -44,6 +45,7 @@ PERF_TEST_P(orb, extract, testing::Values(ORB_IMAGES))
ORB detector(1500, 1.3f, 5);
vector<KeyPoint> points;
detector(frame, mask, points);
sort(points.begin(), points.end(), comparators::KeypointGreater());
Mat descriptors;
......@@ -69,6 +71,7 @@ PERF_TEST_P(orb, full, testing::Values(ORB_IMAGES))
TEST_CYCLE() detector(frame, mask, points, descriptors, false);
perf::sort(points, descriptors);
SANITY_CHECK_KEYPOINTS(points);
SANITY_CHECK(descriptors);
}
......@@ -510,7 +510,25 @@ struct CV_EXPORTS RectLess_
typedef RectLess_<int> RectLess;
struct CV_EXPORTS KeypointGreater
{
bool operator()(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2) const
{
if(kp1.response > kp2.response) return true;
if(kp1.response < kp2.response) return false;
if(kp1.size > kp2.size) return true;
if(kp1.size < kp2.size) return false;
if(kp1.octave > kp2.octave) return true;
if(kp1.octave < kp2.octave) return false;
if(kp1.pt.y < kp2.pt.y) return false;
if(kp1.pt.y > kp2.pt.y) return true;
return kp1.pt.x < kp2.pt.x;
}
};
} //namespace comparators
void CV_EXPORTS sort(std::vector<cv::KeyPoint>& pts, cv::InputOutputArray descriptors);
} //namespace perf
#endif //__OPENCV_TS_PERF_HPP__
......@@ -1246,6 +1246,51 @@ TestBase::_declareHelper::_declareHelper(TestBase* t) : test(t)
{
}
/*****************************************************************************************\
* miscellaneous
\*****************************************************************************************/
namespace {
struct KeypointComparator
{
std::vector<cv::KeyPoint>& pts_;
comparators::KeypointGreater cmp;
KeypointComparator(std::vector<cv::KeyPoint>& pts) : pts_(pts), cmp() {}
bool operator()(int idx1, int idx2) const
{
return cmp(pts_[idx1], pts_[idx2]);
}
};
}//namespace
void perf::sort(std::vector<cv::KeyPoint>& pts, cv::InputOutputArray descriptors)
{
cv::Mat desc = descriptors.getMat();
CV_Assert(pts.size() == (size_t)desc.rows);
cv::AutoBuffer<int> idxs(desc.rows);
for (int i = 0; i < desc.rows; ++i)
idxs[i] = i;
std::sort((int*)idxs, (int*)idxs + desc.rows, KeypointComparator(pts));
std::vector<cv::KeyPoint> spts(pts.size());
cv::Mat sdesc(desc.size(), desc.type());
for(int j = 0; j < desc.rows; ++j)
{
spts[j] = pts[idxs[j]];
cv::Mat row = sdesc.row(j);
desc.row(idxs[j]).copyTo(row);
}
spts.swap(pts);
sdesc.copyTo(desc);
}
/*****************************************************************************************\
* ::perf::GpuPerf
\*****************************************************************************************/
......@@ -1293,7 +1338,3 @@ void PrintTo(const Size& sz, ::std::ostream* os)
} // namespace cv
/*****************************************************************************************\
* ::cv::PrintTo
\*****************************************************************************************/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment