Search code examples
opencvsiftfeature-detectionsurf

Difference between SiftFeatureDetector() and Ptr<FeatureDetector>


Whats the difference between SiftFeatureDetector() and Ptr. They both apparently have the same function. The opencv tutorial uses SiftFeatureDetector but when clicking on the official documentation they use Ptr and have no mention of SiftFeatureDetector(), so I cant read up on it. as in the tutorial they used this: int minHessian = 400; SurfFeatureDetector detector( minHessian ); and I dont know what the minHessian is supposed to do.

Also I tried them both on the same image and they both have the same result, then why are they different?

int _tmain(int argc, _TCHAR* argv[])
{
//initModule_nonfree();
Mat img;

img = imread("c:\\box.png", 0);

//cvtColor( img, gry, CV_BGR2GRAY );

 //SiftFeatureDetector detector;
//vector<KeyPoint> keypoints;
//detector.detect(img, keypoints);

Ptr<FeatureDetector> feature_detector = FeatureDetector::create("SIFT");
vector<KeyPoint> keypoints;

feature_detector->detect(img, keypoints);

Mat output;

drawKeypoints(img, keypoints, output, Scalar::all(-1));

namedWindow("meh", CV_WINDOW_AUTOSIZE);
imshow("meh", output);
waitKey(0);



return 0;

}

Thank you


Solution

  • EDIT: See the correction by @gantzer89 in the comments below. (Leaving my original text in place for historical clarity.)


    In my general experience, using the FeatureDetector::create() syntax (discussed here in the "official documentation" you cited) allows the flexibility to specify your algorithm at runtime via a parameter file, while the more specific classes, such as SiftFeatureDetector, provide more opportunities for customization.

    The create() methods start with a set of default algorith-specific parameters, while the algorithim-specific classes allow customization of these parameters upon construction. Thus, the create() method is assigning a default value to minHessian, while the SiftFeatureDetector constructor provides the opportunity to choose a value of minHessian.

    As a rule of thumb, if you want to quickly experiment with which algorithm to use, use the create() syntax, and if you want to experiment with fine-tuning a particular algorithm, use the algorithm-specific class constructor.