Add methods to sort keypoints and corresponding descriptors
This commit is contained in:
parent
18295bc778
commit
97640847c5
@ -27,6 +27,7 @@ PERF_TEST_P(orb, detect, testing::Values(ORB_IMAGES))
|
|||||||
|
|
||||||
TEST_CYCLE() detector(frame, mask, points);
|
TEST_CYCLE() detector(frame, mask, points);
|
||||||
|
|
||||||
|
sort(points.begin(), points.end(), comparators::KeypointGreater());
|
||||||
SANITY_CHECK_KEYPOINTS(points);
|
SANITY_CHECK_KEYPOINTS(points);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ PERF_TEST_P(orb, extract, testing::Values(ORB_IMAGES))
|
|||||||
ORB detector(1500, 1.3f, 5);
|
ORB detector(1500, 1.3f, 5);
|
||||||
vector<KeyPoint> points;
|
vector<KeyPoint> points;
|
||||||
detector(frame, mask, points);
|
detector(frame, mask, points);
|
||||||
|
sort(points.begin(), points.end(), comparators::KeypointGreater());
|
||||||
|
|
||||||
Mat descriptors;
|
Mat descriptors;
|
||||||
|
|
||||||
@ -69,6 +71,7 @@ PERF_TEST_P(orb, full, testing::Values(ORB_IMAGES))
|
|||||||
|
|
||||||
TEST_CYCLE() detector(frame, mask, points, descriptors, false);
|
TEST_CYCLE() detector(frame, mask, points, descriptors, false);
|
||||||
|
|
||||||
|
perf::sort(points, descriptors);
|
||||||
SANITY_CHECK_KEYPOINTS(points);
|
SANITY_CHECK_KEYPOINTS(points);
|
||||||
SANITY_CHECK(descriptors);
|
SANITY_CHECK(descriptors);
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,25 @@ struct CV_EXPORTS RectLess_
|
|||||||
|
|
||||||
typedef RectLess_<int> 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
|
} //namespace comparators
|
||||||
|
|
||||||
|
void CV_EXPORTS sort(std::vector<cv::KeyPoint>& pts, cv::InputOutputArray descriptors);
|
||||||
} //namespace perf
|
} //namespace perf
|
||||||
|
|
||||||
#endif //__OPENCV_TS_PERF_HPP__
|
#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
|
* ::perf::GpuPerf
|
||||||
\*****************************************************************************************/
|
\*****************************************************************************************/
|
||||||
@ -1293,7 +1338,3 @@ void PrintTo(const Size& sz, ::std::ostream* os)
|
|||||||
|
|
||||||
} // namespace cv
|
} // namespace cv
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************************\
|
|
||||||
* ::cv::PrintTo
|
|
||||||
\*****************************************************************************************/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user