• 大小: 11KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: Html/CSS
  • 标签: opencv  feature  match  

资源简介

博客 http://www.cnblogs.com/wangguchangqing/p/4333873.html 中的demo代码,鉴于有很多人想参考下,就上传到这了。 主要是匹配后,计算两视图的基础矩阵F,然后再除去不适合的匹配点. 代码中 好像还有一部分三角计算的代码

资源截图

代码片段和文件信息

#include “FeatureMatchTest.h“
#include 

using namespace std;
using namespace cv;

FeatureMatchTest::FeatureMatchTest(std::shared_ptr left std::shared_ptr right std::shared_ptrriptorMatcher> matcher) :
leftPattern(left) rightPattern(right) matcher(matcher) {

//step1:Create detector
int minHessian = 400;
SurfFeatureDetector detector(minHessian);

//step2:Detecte keypoint
detector.detect(leftPattern->image leftPattern->keypoints);
detector.detect(rightPattern->image rightPattern->keypoints);

//step3:Compute descriptor
detector.compute(leftPattern->image leftPattern->keypoints leftPattern->descriptors);
detector.compute(rightPattern->image rightPattern->keypoints rightPattern->descriptors);
}

void FeatureMatchTest::match(vector& matches) {

matcher->match(leftPattern->descriptors rightPattern->descriptors matches);
}

void FeatureMatchTest::knnMatch(vector& matches) {

const float minRatio = 1.f / 1.5f;
const int k = 2;

vector> knnMatches;
matcher->knnMatch(leftPattern->descriptors rightPattern->descriptors knnMatches k);

for (size_t i = 0; i < knnMatches.size(); i++) {
const DMatch& bestMatch = knnMatches[i][0];
const DMatch& betterMatch = knnMatches[i][1];

float  distanceRatio = bestMatch.distance / betterMatch.distance;
if (distanceRatio < minRatio)
matches.push_back(bestMatch);
}
}

void FeatureMatchTest::refineMatcheswithHomography(vector& matches double reprojectionThreshold Mat& homography){
const int minNumbermatchesAllowed = 8;
if (matches.size() < minNumbermatchesAllowed)
return;

//Prepare data for findHomography
vector srcPoints(matches.size());
vector dstPoints(matches.size());

for (size_t i = 0; i < matches.size(); i++) {
srcPoints[i] = rightPattern->keypoints[matches[i].trainIdx].pt;
dstPoints[i] = leftPattern->keypoints[matches[i].queryIdx].pt;
}

//find homography matrix and get inliers mask
vector inliersMask(srcPoints.size());
homography = findHomography(srcPoints dstPoints CV_FM_RANSAC reprojectionThreshold inliersMask);

vector inliers;
for (size_t i = 0; i < inliersMask.size(); i++){
if (inliersMask[i])
inliers.push_back(matches[i]);
}
matches.swap(inliers);
}

void FeatureMatchTest::refineMatchesWithFundmentalMatrix(vector& matches Mat& F) {
//Align all points
vector alignedKps1 alignedKps2;
for (size_t i = 0; i < matches.size(); i++) {
alignedKps1.push_back(leftPattern->keypoints[matches[i].queryIdx]);
alignedKps2.push_back(rightPattern->keypoints[matches[i].trainIdx]);
}

//Keypoints to points
vector ps1 ps2;
for (unsigned i = 0; i < alignedKps1.size(); i++)
ps1.push_back(alignedKps1[i].pt);

for (unsigned i = 0; i < alignedKps2.size(); i++)
ps2.push_back(alignedKps2[i].pt);

//Compute 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4365  2015-03-26 20:34  FeatureMatchDemo\FeatureMatchDemo\FeatureMatchDemo.vcxproj

     文件       1174  2015-03-11 22:16  FeatureMatchDemo\FeatureMatchDemo\FeatureMatchDemo.vcxproj.filters

     文件       4035  2015-03-11 22:40  FeatureMatchDemo\FeatureMatchDemo\FeatureMatchTest.cpp

     文件       1000  2015-03-11 22:45  FeatureMatchDemo\FeatureMatchDemo\FeatureMatchTest.h

     文件       1219  2015-03-26 14:58  FeatureMatchDemo\FeatureMatchDemo\main.cpp

     文件       3956  2015-03-26 21:25  FeatureMatchDemo\FeatureMatchDemo\Triangulation.cpp

     文件        862  2015-03-26 20:43  FeatureMatchDemo\FeatureMatchDemo\Triangulation.h

     文件        994  2015-03-08 22:58  FeatureMatchDemo\FeatureMatchDemo.sln

    ..A..H.     34816  2017-01-04 23:02  FeatureMatchDemo\FeatureMatchDemo.v12.suo

     目录          0  2017-01-04 23:01  FeatureMatchDemo\FeatureMatchDemo

     目录          0  2017-01-04 23:02  FeatureMatchDemo

----------- ---------  ---------- -----  ----

                52421                    11


评论

共有 条评论