OpenCV之图像特征提取与检测(十八) Brisk特征检测与匹配

Brisk(Binary Robust Invariant Scalable Keypoints)特征 相比于 SURF SIFT 有些步骤是相同的
    构建尺度空间
    特征点检测
    FAST9-16寻找特征   连续 9-16 个点小于或大于当前值,就把其当作特征点的候选者
    特征点定位
    关键点描述子

这里写图片描述

代码

    #include "../common/common.hpp"

    void main(int argc, char** argv)
    {
        Mat img1 = imread(getCVImagesPath("images/box.png"), IMREAD_GRAYSCALE);
        Mat img2 = imread(getCVImagesPath("images/box_in_scene.png"), IMREAD_GRAYSCALE);
        imshow("box image", img1);
        imshow("scene image", img2);

        // extract BRISK features
        Ptr<Feature2D> detector = BRISK::create(); // BRISK特征检测类
        vector<KeyPoint> keypoints_obj;
        vector<KeyPoint> keypoints_scene;
        Mat descriptor_obj, descriptor_scene;
        detector->detectAndCompute(img1, Mat(), keypoints_obj, descriptor_obj); // BRISK特征检测,并计算生成特征描述子
        detector->detectAndCompute(img2, Mat(), keypoints_scene, descriptor_scene);
        cout << "keypoints_obj.size=" << keypoints_obj.size() << endl; // keypoints_obj.size=1663
        cout << "keypoints_scene.size=" << keypoints_scene.size() << endl; // keypoints_scene.size = 2785
        // descriptor_obj depth = 0, type = 0, size = [64 x 1663]
        cout << "descriptor_obj depth=" << descriptor_obj.depth() << ", type=" << descriptor_obj.type() << ", size=" << descriptor_obj.size() << endl;
        // descriptor_scene depth = 0, type = 0, size = [64 x 2785]
        cout << "descriptor_scene depth=" << descriptor_scene.depth() << ", type=" << descriptor_scene.type() << ", size=" << descriptor_scene.size() << endl;

        // matching
        BFMatcher matcher(NORM_L2);
        vector<DMatch> matches;
        matcher.match(descriptor_obj, descriptor_scene, matches); // 匹配
        // draw matches
        Mat matchesImg;
        drawMatches(img1, keypoints_obj, img2, keypoints_scene, matches, matchesImg);
        imshow("BRISK MATCH RESULT", matchesImg);

        // BRISK 特征检测,其检测出来的特征是比较精准的
        Mat girl = imread(getCVImagesPath("images/test1_3.png"), IMREAD_GRAYSCALE);
        imshow("src2-25", girl);
        vector<KeyPoint> keypoints;
        detector->detect(girl, keypoints, Mat());
        //  draw key points
        Mat resultImg;
        drawKeypoints(girl, keypoints, resultImg, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
        imshow("Brisk Key Points", resultImg);

        waitKey(0);
    }

效果图

这里写图片描述

猜你喜欢

转载自blog.csdn.net/huanghuangjin/article/details/81292726