ORB算法特征匹配

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxzxxzdlut/article/details/72967596

ORB算法是brief算法的改进版。ORB算法比SIFT算法效率高两个数量级。计算速度上ORB是SIFT的100倍,是SURF的10倍。综合性能是最好的。
ORB算法没有解决brief算法的不具备尺度不变性的缺点。但是因为是追求速度的算法,常常适用于视屏流的处理,可以通过跟踪或者一些启发式的策略来解决尺度不变性的问题。
在给出的程序代码中,使用了基于FLANN的描述符对象匹配。
高维数据的快速最近邻算法FLANN
程序中使用的是LinearIndexParams,该结构对应的索引进行线性的、暴力(brute-force)的搜索。
其他的还有基于kd树的索引。
KNN算法与Kd树
kd树原理比较复杂。。。。。。以后有时间再看。。。。。。。。

#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/features2d/features2d.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include<iostream>
using namespace std;
using namespace cv;

int main()
{
    Mat srcImage = imread("1.jpg",1);
    imshow("原始图",srcImage);
    Mat srcImage_gray;
    cvtColor(srcImage,srcImage_gray,CV_BGR2GRAY);

    Ptr<ORB> Detector = ORB::create(400);
    Ptr<ORB> Extrator = ORB::create();
    vector<KeyPoint>keyPoints;
    Mat descriptor;
    Detector->detect(srcImage_gray,keyPoints);
    Extrator->compute(srcImage_gray,keyPoints,descriptor);

    flann::Index flannIndex(descriptor,flann::LshIndexParams(12,20,2),cvflann::FLANN_DIST_HAMMING);

    VideoCapture cap(0);
    cap.set(CV_CAP_PROP_FRAME_WIDTH,360);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT,900);

    unsigned int frameCount = 0;

    while (1)
    {
        double time0 = static_cast<double>(getTickCount());
        Mat captureImage, captureImage_gray;
        cap >> captureImage;
        if (captureImage.empty())
            continue;
        cvtColor(captureImage,captureImage_gray,CV_BGR2GRAY);

        vector<KeyPoint>captureKeyPoints;
        Mat captureDescriptor;
        Detector->detect(captureImage_gray,captureKeyPoints);
        Extrator->compute(captureImage_gray,captureKeyPoints,captureDescriptor);

        Mat matchIndex(captureDescriptor.rows, 2, CV_32SC1);
        Mat matchDistance(captureDescriptor.rows,2,CV_32FC1);
        flannIndex.knnSearch(captureDescriptor,matchIndex,matchDistance,2,flann::SearchParams());

        vector<DMatch>goodMatches;
        for (int i = 0; i < matchDistance.rows; i++)
        {
            if (matchDistance.at<float>(i, 0) < 0.6*matchDistance.at<float>(i, 1))
            {
                DMatch dmarches(i, matchIndex.at<int>(i, 0), matchDistance.at<float>(i, 0));
                goodMatches.push_back(dmarches);
            }
        }

        Mat resultImage;
        drawMatches(captureImage,captureKeyPoints,srcImage,keyPoints,goodMatches,resultImage);
        imshow("匹配窗口",resultImage);

        cout << "帧率:" << getTickFrequency() / (getTickCount() - time0) << endl;

        if (char(waitKey(1) == 27))break;
    }![这里写图片描述](http://img.blog.csdn.net/20170609181804860?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHh6eHh6ZGx1dA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
    return 0;
}

这里写图片描述
这里写图片描述
这里写图片描述
可见帧率比起SURF算法要高出很多。
opencv3.2 SURF实现特征点匹配

猜你喜欢

转载自blog.csdn.net/xxzxxzdlut/article/details/72967596
今日推荐