OpenCV角點檢測器測試和比較

關於特徵檢測,OpenCV提供了通用的接口FeatureDetector類。簡單調用其成員函數create()detect()即可完成角點檢測。

選取8個以角點爲特徵的特徵檢測器進行測試,包括:

  • HARRIS
  • GFTT (Shi-tomasi)
  • SIFT
  • SURF
  • FAST
  • STAR
  • ORB (oriented BRIEF)
  • BRISK

測試代碼

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"

using namespace cv;
using namespace std;

int main()
{
    string imgPath = "road.jpg";
    Mat img = imread(imgPath, CV_LOAD_IMAGE_COLOR);

    vector<string> detectorNames{"HARRIS","GFTT","SIFT",
        "SURF","FAST","STAR","ORB","BRISK"};

    cout << "DetectorName" << '\t' 
        << "Number of corners" << '\t' 
        << "Time used" <<'\t'<<"efficiency" 
        << endl << endl;

    for (string detectorName:detectorNames)
    {
        cout <<detectorName<<+"\t\t";
        double t = (double)getTickCount();

        //--detect keypoints
        Ptr<FeatureDetector> detector 
            = FeatureDetector::create(detectorName);
        vector<KeyPoint> keyPoints;
        detector->detect(img, keyPoints, Mat());
        cout << keyPoints.size() << "\t\t\t";

        //--draw keypoints
        Mat imgKeyPoints;
        drawKeypoints(img, keyPoints, imgKeyPoints, 
            Scalar::all(-1), DrawMatchesFlags::DEFAULT);

        imshow(detectorName+" KeyPoints", imgKeyPoints);

        //time used
        t = ((double)getTickCount() - t) / getTickFrequency();
        cout << t << "\t";

        //Number of coners detected per unit time(ms)
        double efficiency = keyPoints.size() / t / 1000;
        cout  << efficiency << endl<<endl;
    }

    waitKey(0);
    return 0;
}

運行結果

HARRIS
這裏寫圖片描述

GFTT
這裏寫圖片描述

SIFT
這裏寫圖片描述

SURF
這裏寫圖片描述

FAST
這裏寫圖片描述

STAR
這裏寫圖片描述

ORB
這裏寫圖片描述

BRISK
這裏寫圖片描述

比較

這裏寫圖片描述

可以看出,FAST特徵檢測算法的檢測速度是超羣的,難怪敢自稱“FAST”。從特徵點檢測效率以及檢測出的特徵點數來看,SURF表現也不錯。以上各個角點檢測器,使用的都是OpenCV默認的封裝,可能會因爲具體的參數設置差異,檢測出的角點數有不同,可比性沒法說明。但是,特徵點檢測效率還是很客觀的。由以上結果得知,檢測效率最高的前3個檢測器分別爲FAST,ORB,SURF。

發佈了75 篇原創文章 · 獲贊 127 · 訪問量 40萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章