加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

OpenCV图像匹配算法之surf

发布时间:2020-12-16 07:46:16 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 //surf.cpp #include "stdafx.h" #include cv.hpp #include highgui.h #include "utils.h" #include iostream using namespace std; void surf(char*

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

    //surf.cpp  
    #include "stdafx.h"  
    #include <cv.hpp>  
    #include <highgui.h>  
    #include "utils.h"  
    #include <iostream>  
    using namespace std;  
      
    void surf(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);  
        }  
      
        int minHessian=200;  
        SurfFeatureDetector surf_detector(minHessian) ;  
        SurfDescriptorExtractor surf_descriptor ;    
        vector<KeyPoint> kpts1_surf,kpts2_surf;  
        Mat desc1_surf,desc2_surf;  
        Ptr<cv::DescriptorMatcher> matcher_l2 = DescriptorMatcher::create("BruteForce");          //欧氏距离匹配  
        vector<vector<DMatch> > dmatches_surf;  
        vector<Point2f> matches_surf,inliers_surf;  
          
        surf_detector.detect(img1,kpts1_surf);  
        surf_detector.detect(img2,kpts2_surf);  
        info.n1 = kpts1_surf.size();  
        info.n2 = kpts2_surf.size();  
      
        surf_descriptor.compute(img1,kpts1_surf,desc1_surf);  
        surf_descriptor.compute(img2,kpts2_surf,desc2_surf);  
        matcher_l2->knnMatch(desc1_surf,desc2_surf,dmatches_surf,2);  
        matches2points_nndr(kpts1_surf,matches_surf,DRATIO);  
        info.m=matches_surf.size()/2;  
        compute_inliers_ransac(matches_surf,inliers_surf,MIN_H_ERROR,false);  
        info.rm=inliers_surf.size()/2;  
      
        t2=cvGetTickCount();  
        info.t=(t2-t1)/1000000.0/cvGetTickFrequency();  
      
        Mat img1_rgb_surf = imread(path1,1);  
        Mat img2_rgb_surf = imread(path2,1);  
        Mat img_com_surf = Mat(Size(img1.cols*2,img1.rows),CV_8UC3);  
      
        if(show == true)  
        {  
            draw_inliers(img1_rgb_surf,img2_rgb_surf,img_com_surf,2);  
            imshow("surf",img_com_surf);  
            waitKey(0);  
        }  
      
        return;  
    }  

使用
    INFO surf_info;  
    surf(path1,path2,surf_info,false);  
    showInfo(surf_info);  

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读