opencv::AKAZE检测与匹配

AKAZE局部匹配

AKAZE局部匹配介绍 
    AOS 构造尺度空间 
    Hessian矩阵特征点检测 
    方向指定基于一阶微分图像 
    描述子生成 
    
与SIFT、SUFR比较 
    更加稳定 
    非线性尺度空间 
    AKAZE速度更加快 
    比较新的算法,只有OpenCV新版本才可以用 
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    Mat src = imread("D:/vcprojects/images/test.png", IMREAD_GRAYSCALE);
    if (src.empty()) {
        printf("could not load image...
");
        return -1;
    }
    imshow("input image", src);

    // kaze detection
    Ptr<AKAZE> detector = AKAZE::create();
    vector<KeyPoint> keypoints;
    double t1 = getTickCount();
    detector->detect(src, keypoints, Mat());
    double t2 = getTickCount();
    double tkaze = 1000 * (t2 - t1) / getTickFrequency();
    printf("KAZE Time consume(ms) : %f", tkaze);

    Mat keypointImg;
    drawKeypoints(src, keypoints, keypointImg, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
    imshow("kaze key points", keypointImg);

    waitKey(0);
    return 0;
}
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    Mat img1 = imread("D:/vcprojects/images/box.png", IMREAD_GRAYSCALE);
    Mat img2 = imread("D:/vcprojects/images/box_in_scene.png", IMREAD_GRAYSCALE);
    if (img1.empty() || img2.empty()) {
        printf("could not load images...
");
        return -1;
    }
    imshow("box image", img1);
    imshow("scene image", img2);

    
    // extract akaze features
    Ptr<AKAZE> detector = AKAZE::create();
    vector<KeyPoint> keypoints_obj;
    vector<KeyPoint> keypoints_scene;
    Mat descriptor_obj, descriptor_scene;
    double t1 = getTickCount();
    detector->detectAndCompute(img1, Mat(), keypoints_obj, descriptor_obj);
    detector->detectAndCompute(img2, Mat(), keypoints_scene, descriptor_scene);
    double t2 = getTickCount();
    double tkaze = 1000 * (t2 - t1) / getTickFrequency();
    printf("AKAZE Time consume(ms) : %f
", tkaze);
    
    // matching
    FlannBasedMatcher matcher(new flann::LshIndexParams(20, 10, 2));
    //FlannBasedMatcher matcher;
    vector<DMatch> matches;
    matcher.match(descriptor_obj, descriptor_scene, matches);
    
    // draw matches(key points)
    Mat akazeMatchesImg;
    drawMatches(img1, keypoints_obj, img2, keypoints_scene, matches, akazeMatchesImg);
    imshow("akaze match result", akazeMatchesImg);
    
    /*
    vector<DMatch> goodMatches;
    double minDist = 100000, maxDist = 0;
    for (int i = 0; i < descriptor_obj.rows; i++) {
        double dist = matches[i].distance;
        if (dist < minDist) {
            minDist = dist;
        }
        if (dist > maxDist) {
            maxDist = dist;
        }
    }
    printf("min distance : %f", minDist);

    for (int i = 0; i < descriptor_obj.rows; i++) {
        double dist = matches[i].distance;
        if (dist < max( 1.5*minDist, 0.02)) {
            goodMatches.push_back(matches[i]);
        }
    }

    drawMatches(img1, keypoints_obj, img2, keypoints_scene, goodMatches, akazeMatchesImg, Scalar::all(-1), 
        Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
    imshow("good match result", akazeMatchesImg);
    */
    
    waitKey(0);
    return 0;
}
原文地址:https://www.cnblogs.com/osbreak/p/11649118.html