• “SurfFeatureDetector”: 未声明的标识符/不能实例化抽象类


    《OpenCV3编程入门》配套示例程序89:SURF特征点检测示例中,出现的问题及解决方法:


    问题一:

    直接按照原文代码写,报错“SurfFeatureDetector”: 未声明的标识符

    	.......
    //【2】定义需要用到的变量和类 int minHessian = 400;//定义SURF中的hessian阈值特征点检测算子 SurfFeatureDetector detector( minHessian );//定义一个SurfFeatureDetector(SURF) 特征检测类对象 std::vector<KeyPoint> keypoints_1, keypoints_2;//vector模板类是能够存放任意类型的动态数组,能够增加和压缩数据 //【3】调用detect函数检测出SURF特征关键点,保存在vector容器中 detector.detect( srcImage1, keypoints_1 ); detector.detect( srcImage2, keypoints_2 );
    .......

      解决方法:

    头文件加上:(SURF算法在opencv3中是nonfree的)

    //OpenCV
    #include <opencv/cv.hpp>
    #include<xfeatures2d/nonfree.hpp>
    #include "opencv2/core/core.hpp"
    #include "opencv2/features2d/features2d.hpp"
    #include "opencv2/highgui/highgui.hpp"
    

      最重要的是加上:

    using namespace xfeatures2d;
    

      (试了一下,头文件加上各种.hpp后还是报错未声明标识符,加上这句话就OK了)

    问题二:

    进行以上操作后,又会出现新的报错"SurfFeatureDetector”: 不能实例化抽象类",需要将代码改为:

    //SURF特征点检测
    cv::Mat BasicAlgorithm::on_SURF(cv::Mat mat)
    {
        //【1】载入源图片并显示
        Mat srcImage1 = mat;
        Mat srcImage2= imread("C:\Users\asus\Desktop\2.jpg");
        
        //【2】定义需要用到的变量和类
        int minHessian = 400; //定义SUFR中的hessian阈值特征点检测算子
        //SurfFeatureDetector detector( minHessian );//定义一个SurfFeatureDetector(SURF) 特征检测类对象(opencv2中或许可用,opencv3这么写就会报错),改为下边这句
        Ptr<SURF>detector = SURF::create(minHessian);
        vector<KeyPoint> keypoints_1, keypoints_2;//vector模板类是能够存放任意类型的动态数组,能够增加和压缩数据
        
        //【3】调用detect函数检测出SURF特征关键点,保存在vector容器中
        detector->detect(srcImage1, keypoints_1);
        detector->detect(srcImage2, keypoints_2);
        
        
        //【4】绘制特征关键点.
        Mat img_keypoints_1; Mat img_keypoints_2;
        drawKeypoints( srcImage1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
        drawKeypoints( srcImage2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
        
        //【5】显示效果图
        imshow("特征点检测效果图1", img_keypoints_1 );
        imshow("特征点检测效果图2", img_keypoints_2 );
        return img_keypoints_1;
    }
    

      以上,SURF特征点检测的完整代码。

    总结:

    SURF在3.1.0下的用法如下:

    SurfFeatureDetector detector( minHessian );
    detector.detect(image,keypoints);

      改为:

    Ptr<SURF>detector = SURF::create();
    detector->detect(image,keypoints);

      

  • 相关阅读:
    tensorflow2.0——tensorboard与预测代码相结合
    tensorflow2.0——tensorboard画图使用
    tensorflow2.0——手写数据集预测完整版
    tensorflow2.0——交叉熵损失应用
    tensorflow2.0——softmax函数
    tensorflow2.0——多层全连接模板
    python基础知识
    day31(模块和包)
    day26(模块 logging 高级用法、collection、random)
    day7 set集合
  • 原文地址:https://www.cnblogs.com/zzzsj/p/14504627.html
Copyright © 2020-2023  润新知