Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve feature type from OpenCV FeatureDetector

Tags:

c++

opencv

In OpenCV, it is very common to create a cv::FeatureDetector by providing the name of the feature:

cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create("SURF");

This is a factory pattern, being cv::FeatureDetector an abstract class.

Then, given a variable of type cv::Ptr<cv::FeatureDetector>, is it possible to retrieve the name of the feature? It is "SURF" in my example.

like image 714
ChronoTrigger Avatar asked Mar 20 '23 20:03

ChronoTrigger


1 Answers

Classes derived from cv::Algorithm inherit a name() method which returns a string containing the algorithm name. In the case of your SURF detector, name() returns the string

Feature2D.SURF

which is a human-readable form. In general, this string is of the form algorithm-type.instance-name, though a very few just have a single-word description. For any of the feature detection algorithms, the algorithm-type prefix is always Feature2D. You can parse it yourself if you need an exact string match.

auto surf = cv::FeatureDetector::create("SURF");
auto n = surf->name();
std::cout << n << std::endl; // Prints "Feature2D.SURF", sans quotes
like image 147
Aurelius Avatar answered Mar 23 '23 01:03

Aurelius