OpenCV图像匹配算法之brisk

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    //brisk.cpp  
    #include "stdafx.h"  
    #include <cv.hpp>  
    #include <highgui.h>  
    #include "utils.h"  
    #include <iostream>  
    using namespace std;  
      
    void brisk(char* path1, char* path2, INFO& info, bool show)  
    {  
        double t1,t2;  
        t1=cvGetTickCount();  
      
        initModule_nonfree();  
      
        Mat img1, img2;  
        img1=imread(path1,0);  
        img2=imread(path2,0);  
        if(img1.data==NULL)  
        {  
            cout<<"The image can not been loaded: "<<path1<<endl;  
            system("pause");  
            exit(-1);  
        }  
        if(img2.data==NULL)  
        {  
            cout<<"The image can not been loaded: "<<path2<<endl;  
            system("pause");  
            exit(-1);  
        }  
      
        BRISK dbrisk(BRISK_HTHRES,BRISK_NOCTAVES);  
        vector<KeyPoint> kpts1_brisk, kpts2_brisk;  
        Mat desc1_brisk, desc2_brisk;  
        Ptr<cv::DescriptorMatcher> matcher_l1 = DescriptorMatcher::create("BruteForce-Hamming");      //二进制汉明距离匹配  
        vector<vector<DMatch> > dmatches_brisk;  
        vector<Point2f> matches_brisk, inliers_brisk;  
          
        dbrisk(img1,noArray(),kpts1_brisk,desc1_brisk,false);  
        dbrisk(img2,noArray(),kpts2_brisk,desc2_brisk,false);  
        info.n1=kpts1_brisk.size();  
        info.n2=kpts2_brisk.size();  
      
        matcher_l1->knnMatch(desc1_brisk,desc2_brisk,dmatches_brisk,2);  
        matches2points_nndr(kpts1_brisk,kpts2_brisk,dmatches_brisk,matches_brisk,DRATIO);  
        info.m=matches_brisk.size()/2;  
        compute_inliers_ransac(matches_brisk,inliers_brisk,MIN_H_ERROR,false);  
        info.rm=inliers_brisk.size()/2;  
      
        t2=cvGetTickCount();  
        info.t=(t2-t1)/1000000.0/cvGetTickFrequency();  
      
        Mat img1_rgb_brisk = imread(path1,1);  
        Mat img2_rgb_brisk = imread(path2,1);  
        Mat img_com_brisk = Mat(Size(img1.cols*2,img1.rows),CV_8UC3);  
      
        if(show == true)  
        {  
            draw_inliers(img1_rgb_brisk,img2_rgb_brisk,img_com_brisk,inliers_brisk,2);  
            imshow("brisk",img_com_brisk);  
            waitKey(0);  
        }  
      
        return;  
    }  

使用
    INFO brisk_info;  
    brisk(path1,path2,brisk_info,false);  
    showInfo(brisk_info);