本文整理汇总了C++中cv::Ptr::knnMatch方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::knnMatch方法的具体用法?C++ Ptr::knnMatch怎么用?C++ Ptr::knnMatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Ptr
的用法示例。
在下文中一共展示了Ptr::knnMatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: crossCheckMatching
void crossCheckMatching( cv::Ptr<DescriptorMatcher>& descriptorMatcher,
const Mat& descriptors1, const Mat& descriptors2,
vector<DMatch>& filteredMatches12, int knn )
{
filteredMatches12.clear();
vector<vector<DMatch> > matches12, matches21;
descriptorMatcher->knnMatch( descriptors1, descriptors2, matches12, knn );
descriptorMatcher->knnMatch( descriptors2, descriptors1, matches21, knn );
for( size_t m = 0; m < matches12.size(); m++ )
{
bool findCrossCheck = false;
for( size_t fk = 0; fk < matches12[m].size(); fk++ )
{
DMatch forward = matches12[m][fk];
for( size_t bk = 0; bk < matches21[forward.trainIdx].size(); bk++ )
{
DMatch backward = matches21[forward.trainIdx][bk];
if( backward.trainIdx == forward.queryIdx )
{
filteredMatches12.push_back(forward);
findCrossCheck = true;
break;
}
}
if( findCrossCheck ) break;
}
}
}
示例2: crossCheckMatching
void crossCheckMatching(
const cv::Mat& descriptors_0, const cv::Mat& descriptors_1,
std::vector<cv::DMatch>& matches, int knn = 1)
{
matches.clear();
std::vector<std::vector<cv::DMatch> > matches12, matches21;
matcher_->knnMatch(descriptors_0, descriptors_1, matches12, knn);
matcher_->knnMatch(descriptors_1, descriptors_0, matches21, knn);
for (size_t m = 0; m < matches12.size(); ++m)
{
bool findCrossCheck = false;
for(size_t fk = 0; fk < matches12[m].size(); ++fk)
{
cv::DMatch forward = matches12[m][fk];
for (size_t bk = 0; bk < matches21[forward.trainIdx].size(); ++bk)
{
cv::DMatch backward = matches21[forward.trainIdx][bk];
if (backward.trainIdx == forward.queryIdx)
{
matches.push_back(forward);
findCrossCheck = true;
break;
}
}
if (findCrossCheck) break;
}
}
}