zoukankan      html  css  js  c++  java
  • OpenCv sift算法 图像特征匹配

    基于OpenCv 2.4.6

     1 #include "highgui.h"
     2 
     3 //#include "features2d/features2d.hpp"//
     4 #include <opencv2/nonfree/features2d.hpp>
     5 #include<opencv2/legacy/legacy.hpp>
     6 #include <iostream>
     7 using namespace std;
     8 using namespace cv;
     9 
    10 void main(int argc, char** argv[])
    11 {
    12     Mat input1=imread("Lena.jpg",1);
    13     Mat input2=imread("Lena2.jpg",1);
    14     SiftFeatureDetector detector;
    15     vector<KeyPoint> keypoint1,keypoint2;
    16     detector.detect(input1,keypoint1);
    17 
    18     Mat output1;
    19     drawKeypoints(input1,keypoint1,output1);
    20     imshow("sift_result1.bmp",output1);
    21     imwrite("sift_result1.bmp",output1);
    22 
    23     Mat output2;
    24     SiftDescriptorExtractor extractor;
    25     Mat descriptor1,descriptor2;
    26     BruteForceMatcher<L2<float>> matcher;
    27 
    28     vector<DMatch> matches;
    29     Mat img_matches;
    30     detector.detect(input2,keypoint2);
    31     drawKeypoints(input2,keypoint2,output2);
    32 
    33     imshow("sift_result2.bmp",output2);
    34     imwrite("sift_result2.bmp",output2);
    35 
    36     extractor.compute(input1,keypoint1,descriptor1);
    37     extractor.compute(input2,keypoint2,descriptor2);
    38 
    39     matcher.match(descriptor1,descriptor2,matches);
    40 
    41     drawMatches(input1,keypoint1,input2,keypoint2,matches,img_matches);
    42     imshow("matches",img_matches);
    43     imwrite("matches.jpg",img_matches);
    44 
    45     waitKey();
    46 
    47 
    48 }
    Sift

        

                     Lena                                             Lena2

     

                                              Duang~

  • 相关阅读:
    [thinkphp] 是如何输出一个页面的
    [thinkphp] 获取根目录绝对路径
    onethink 插件模板定位
    win7 安全模式开启声音
    百度贴吧楼层评论地址
    第一天问题
    [php] 解析JSON字符串
    NDK编译时两 .so之间调用问题
    CDN问题积累
    C++模板特化
  • 原文地址:https://www.cnblogs.com/gaohai/p/5786714.html
Copyright © 2011-2022 走看看