使用RANSAC提純KAZE和AKAZE特徵點,達到魯棒匹配的效果(OpenCV 3.2.0下,源碼)

KAZE是EECV 2012年新提出來的特徵點檢測和描述算法,AKAZE是在KAZE基礎上進行改進的,詳細原理參見作者官網和github上的源碼:

http://www.robesafe.com/personal/pablo.alcantarilla/kaze.html


https://github.com/pablofdezalc/akaze


https://github.com/pablofdezalc/kaze


在OpenCV 3.X 下已經集成了該算法


#include 
#include 
#include 
#include 


using namespace std;
using namespace cv;

int main(void)
{
    Mat graf_1 = imread("../data/vggAffineDataset/graf/img1.ppm");
    Mat graf_3 = imread("../data/vggAffineDataset/graf/img3.ppm");

    if (graf_1.empty() || graf_3.empty()){
        cerr<<"No images"< kp1, kp3;
    Mat desc_1, desc_3;
    
    // KAZE特徵 
    Ptr kaze = KAZE::create();
    kaze->detectAndCompute(graf_1, noArray(), kp1, desc_1);
    kaze->detectAndCompute(graf_3, noArray(), kp3, desc_3);
    
    // AKAZE特徵
    //Ptr akaze = AKAZE::create();
    //akaze->detectAndCompute(graf_1, noArray(), kp1, desc_1);
    //akaze->detectAndCompute(graf_3, noArray(), kp3, desc_3);
    
    
    Mat imgKeypoint_1, imgKeypoint_3;
    drawKeypoints(graf_1,kp1,imgKeypoint_1,(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    drawKeypoints(graf_3,kp3,imgKeypoint_3,(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    imshow("keypoints of graf_1", imgKeypoint_1);
    imshow("keypoints of graf_3", imgKeypoint_3);
    imwrite("kp_graf_1.jpg",imgKeypoint_1);
    imwrite("kp_graf_3.jpg",imgKeypoint_3);

    FlannBasedMatcher matcher;
    // AKAZE特徵描述子爲二進制描述子
    // BFMatcher matcher(NORM_HAMMING);
    vector matches;
    matcher.match(desc_1,desc_3,matches,noArray());

    double max_dist = 0;
    double min_dist = 10000;
    for (int i = 0; i < matches.size(); ++i) {
        if (matches[i].distance < min_dist)
            min_dist = matches[i].distance;
        if (matches[i].distance > max_dist)
            max_dist = matches[i].distance;
    }

    vector goodMatches;
    for (int j = 0; j < matches.size(); ++j) {
        if (matches[j].distance < 4*min_dist)
            goodMatches.push_back(matches[j]);
    }
    cout<<"Matches is "<(k,0) = pt1.x;
        p1.at(k,1) = pt1.y;

        pt3 = kp3[goodMatches[k].trainIdx].pt;
        p3.at(k,0) = pt3.x;
        p3.at(k,1) = pt3.y;
    }

    vector m_RANSACStatus;
    findFundamentalMat(p1,p3,m_RANSACStatus,FM_RANSAC);

    int inlinerCount = 0;
    for (int l = 0; l < ptCount; ++l) {
        if (m_RANSACStatus[l] != 0)
            inlinerCount++;
    }
    cout<<"inlinerCount is "< inlierMatches;
    for (int i=0; i

實驗效果圖:


(kp_graf_1)


(kp_graf_3)


(不經過任何處理的圖像匹配)


(使用距離小於最小距離10倍時的匹配效果)


(使用RANSAC算法提純後的圖像匹配效果)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章