1
votes

I´m quite new to OpenCV. I followed this tutorial for searching an object in a picture and I was able to run the code successfully.

While I was searching, I saw that there are more options for feature matching (e.g Fast, ORB or BRISK). So I decided to try a different descriptor than SURF.

But I'm having trouble. What do I have to do to create a different descriptor? Can someone help me, maybe with a code example for OpenCV3.2? :)

This is a link that I have found while searching, but sadly it is not for OpenCV 3.2.

1
Have you looked at examples provided with OpenCV? stackoverflow.com/a/14986422/6331998m3h0w

1 Answers

2
votes

With OpenCV 3 a consistent feature detection API was introduced.

That is, every feature detector implements a static create() method which returns a cv::Ptr to the respective detector.

Here's a quick example which shows the described behaviour:

#include <iostream>
#include <vector>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>


int main(int argc, char *argv[])
{
    if(argc > 1) {
        cv::Mat img = cv::imread(argv[1], cv::ImreadModes::IMREAD_GRAYSCALE);
        if(!img.empty()) {
            cv::Ptr<cv::xfeatures2d::SiftFeatureDetector> siftDetector = cv::xfeatures2d::SiftFeatureDetector::create();
            cv::Ptr<cv::BRISK> briskDetector = cv::BRISK::create();

            std::vector<cv::KeyPoint> siftKeypoints;
            std::vector<cv::KeyPoint> briskKeypoints;

            siftDetector->detect(img, siftKeypoints);
            briskDetector->detect(img, briskKeypoints);

            std::cout << "Detected " << siftKeypoints.size() << " SIFT keypoints." << std::endl;
            std::cout << "Detected " << briskKeypoints.size() << " BRISK keypoints." << std::endl;
            return 0;
        } else {
            std::cout << "Unable to load image, aborting." << std::endl;
            return -1;
        }
    }
    std::cout << "A path to an (image) file is missing." << std::endl;
    return -1;
}

Following this sample you're able to use each of OpenCV's detectors, which are in the latest docs:

Default descriptors

Non-free descriptors

Experimental descriptors