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~

  • 相关阅读:
    java10 var
    java lambda,方法引用
    Java集合总结
    Oracle/Sun JDK与OpenJDK的区别和联系
    IO基本知识
    字符串反转2单词内部不进行转换
    反转String 1
    java 左移<<&>>右移&>>无符号右移
    反射
    equals方法与hashcode方法
  • 原文地址:https://www.cnblogs.com/gaohai/p/5786714.html
Copyright © 2011-2022 走看看