[opencv]KAZE、AKAZE特征檢測、匹配與對象查找


 

AkAZE是KAZE的加速版

與SIFT,SUFR比較:

1.更加穩定

2.非線性尺度空間

3.AKAZE速度更加快

4.比較新的算法,只有Opencv新的版本才可以用

 

AKAZE局部匹配介紹

1.AOS構造尺度空間

2.Hessian矩陣特征點

3.方向指定基於一階微分圖像

4.描述子生成

特征點查找和繪制:把surf中的surf改成KAZE或AKAZE即可

#include <opencv2/opencv.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>

using namespace cv;
using namespace cv::features2d;
using namespace std;

int Akaze feature detection(){
Mat src = imread("test.jpg", IMREAD_GRAYSCALE);
    if (src.empty()) {
        printf("could not load image...\n");
        return -1;
    }
    namedWindow("input image", CV_WINDOW_AUTOSIZE);
    imshow("input image", src);

    // AKAZE特征點檢測
    Ptr<AKAZE> detector = AKAZE::create();//創建一個AKAZE類對象並初始化
    vector<KeyPoint> keypoints;
    detector->detect(src, keypoints, Mat());//找Mat src = imread("test.jpg", IMREAD_GRAYSCALE);
    if (src.empty()) {
        printf("could not load image...\n");
        return -1;
    }
    namedWindow("input image", CV_WINDOW_AUTOSIZE);
    imshow("input image", src);

    // AKAZE特征點檢測
    Ptr<AKAZE> detector = AKAZE::create();//創建一個AKAZE類對象並初始化
    vector<KeyPoint> keypoints;
    detector->detect(src, keypoints, Mat());//找出關鍵點

    // 繪制關鍵點
    Mat keypoint_img;
    drawKeypoints(src, keypoints, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
    imshow("KeyPoints Image", keypoint_img);

    waitKey(0);
    return 0;
}

匹配:

int featurematching{

Mat img1 = imread("/home/leoxae/KeekoRobot/TestPic/qrcodetest/13.png");
Mat img2 = imread("/home/leoxae/KeekoRobot/TestPic/qrcodetest/13.png");

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;
detector->detectAndCompute(img1, Mat(), keypoints_obj, descriptor_obj);
detector->detectAndCompute(img2, Mat(), keypoints_scene, descriptor_scene);


// 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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM