• 匹配


     1 #include "highgui/highgui.hpp"    
     2 #include "opencv2/nonfree/nonfree.hpp"    
     3 #include "opencv2/legacy/legacy.hpp"   
     4 #include <iostream>  
     5 
     6 using namespace cv;
     7 using namespace std;
     8 
     9 
    10 int main()
    11 {
    12     Mat image01 = imread("C:\2.jpg",1);    //右图
    13     Mat image02 = imread("C:\1.jpg", 1);    //左图
    14     namedWindow("p2", 0);
    15     namedWindow("p1", 0);
    16     imshow("p2", image01);
    17     imshow("p1", image02);
    18 
    19     //灰度图转换  
    20     Mat image1, image2;
    21     cvtColor(image01, image1, CV_RGB2GRAY);
    22     cvtColor(image02, image2, CV_RGB2GRAY);
    23 
    24 
    25     //提取特征点    
    26     SurfFeatureDetector surfDetector(12000);  // 海塞矩阵阈值,在这里调整精度,值越大点越少,越精准 
    27     vector<KeyPoint> keyPoint1, keyPoint2;
    28     surfDetector.detect(image1, keyPoint1);
    29     surfDetector.detect(image2, keyPoint2);
    30 
    31     //特征点描述,为下边的特征点匹配做准备    
    32     SurfDescriptorExtractor SurfDescriptor;
    33     Mat imageDesc1, imageDesc2;
    34     SurfDescriptor.compute(image1, keyPoint1, imageDesc1);
    35     SurfDescriptor.compute(image2, keyPoint2, imageDesc2);
    36 
    37     //获得匹配特征点,并提取最优配对     
    38     FlannBasedMatcher matcher;
    39     vector<DMatch> matchePoints;
    40 
    41     matcher.match(imageDesc1, imageDesc2, matchePoints, Mat());
    42     cout << "total match points: " << matchePoints.size() << endl;
    43 
    44 
    45     Mat img_match;
    46     drawMatches(image01, keyPoint1, image02, keyPoint2, matchePoints, img_match);
    47     namedWindow("match", 0);
    48     imshow("match", img_match);
    49     imwrite("match.jpg", img_match);
    50 
    51     waitKey();
    52     return 0;
    53 }
  • 相关阅读:
    关于上传组件
    二分查找的时间复杂度
    commander.js
    执行上下文
    谷歌插件开发
    网站性能
    日记
    <<人间失格>>阅读
    Node.js 应该用在什么地方
    浅谈前后端分离与实践 之 nodejs 中间层服务
  • 原文地址:https://www.cnblogs.com/hsy1941/p/9563030.html
Copyright © 2020-2023  润新知