计算机视觉攻略 笔记7 (尺度不变特征的检测)&(多尺度FAST特征检测)

尺度不变特征的检测

SURF特征(加速稳健特征Speeded Up Robust Feature)

参考博文

surf算法原理

示例程序

#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include </home/jlm/3rdparty/opencv/opencv_contrib/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;

int main(int argc, char** argv) {
    
    
    if(argc != 2)
    {
    
    
        cerr << "don't get the right numbers of image" << endl;
        return -1;
    }
    cv::Mat image = cv::imread(argv[1],cv::IMREAD_GRAYSCALE);
    if(image.empty())
    {
    
    
        cout << "don't get the data of the argv[1]" << endl;
        return -1;
    }
    cv::imshow("Original", image);
    cv::waitKey(0);
    cv::Ptr<cv::xfeatures2d::SurfFeatureDetector> ptrSURF =
            cv::xfeatures2d::SurfFeatureDetector::create(2000.0);

    vector<cv::KeyPoint> Keypoints;
    // 检测关键点信息
    ptrSURF -> detect(image, Keypoints);

    cv::Mat outImage;
    // 画出关键点:包括尺度和方向信息
    cv::drawKeypoints(image,
                      Keypoints,
                      outImage,
                      cv::Scalar(255,255,255),
                      cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS
                      );
//    这里使用 cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS 标志得到了关键点的圆,并
//    且圆的尺寸与每个特征计算得到的尺度成正比。为了使特征具有旋转不变性, SURF 还让每个特
//    征关联了一个方向,由每个圆内的辐射线表示。
    cv::imshow("OutImage",outImage);
    cv::waitKey(0);
    return 0;
}

多尺度FAST特征检测

示例程序

#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include </home/jlm/3rdparty/opencv/opencv_contrib/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;

int main(int argc, char** argv) {
    
    
    if(argc != 2)
    {
    
    
        cerr << "don't get the right numbers of image" << endl;
        return -1;
    }
    cv::Mat image = cv::imread(argv[1],cv::IMREAD_GRAYSCALE);
    if(image.empty())
    {
    
    
        cout << "don't get the data of the argv[1]" << endl;
        return -1;
    }
    cv::imshow("Original", image);
    cv::waitKey(0);
//    cv::Ptr<cv::xfeatures2d::SurfFeatureDetector> ptrSURF =
//            cv::xfeatures2d::SurfFeatureDetector::create(2000.0);
    cv::Ptr<cv::BRISK> ptrBRISK =
            cv::BRISK::create();
    vector<cv::KeyPoint> Keypoints;
    // 检测关键点信息
//    ptrSURF -> detect(image, Keypoints);
    ptrBRISK -> detect(image, Keypoints);

    cv::Mat outImage;
    // 画出关键点:包括尺度和方向信息
    cv::drawKeypoints(image,
                      Keypoints,
                      outImage,
                      cv::Scalar(255,255,255),
                      cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS
                      );
//    这里使用 cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS 标志得到了关键点的圆,并
//    且圆的尺寸与每个特征计算得到的尺度成正比。为了使特征具有旋转不变性, SURF 还让每个特
//    征关联了一个方向,由每个圆内的辐射线表示。
    cv::imshow("OutImage",outImage);
    cv::waitKey(0);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/jlm7689235/article/details/108033314