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