Avoid duplicated surf extraction step when same parameters are used for detection and descriptors calculation

This commit is contained in:
Andrey Kamaev 2011-10-03 08:44:28 +00:00
parent 20af242a03
commit ee413b8026
2 changed files with 22 additions and 5 deletions

View File

@ -79,13 +79,14 @@ class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder
{
public:
SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
int num_octaves_descr = 4, int num_layers_descr = 2);
int num_octaves_descr = /*4*/3, int num_layers_descr = /*2*/4);
private:
void find(const Mat &image, ImageFeatures &features);
Ptr<FeatureDetector> detector_;
Ptr<DescriptorExtractor> extractor_;
Ptr<SURF> surf;
};

View File

@ -292,10 +292,17 @@ void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features, cons
SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int num_layers,
int num_octaves_descr, int num_layers_descr)
{
if (num_octaves_descr == num_octaves && num_layers_descr == num_layers)
{
surf = new SURF(hess_thresh, num_octaves, num_layers);
}
else
{
detector_ = new SurfFeatureDetector(hess_thresh, num_octaves, num_layers);
extractor_ = new SurfDescriptorExtractor(num_octaves_descr, num_layers_descr);
}
}
void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
@ -303,9 +310,18 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
Mat gray_image;
CV_Assert(image.depth() == CV_8U);
cvtColor(image, gray_image, CV_BGR2GRAY);
if (surf == 0)
{
detector_->detect(gray_image, features.keypoints);
extractor_->compute(gray_image, features.keypoints, features.descriptors);
}
else
{
vector<float> descriptors;
(*surf)(gray_image, Mat(), features.keypoints, descriptors);
features.descriptors = Mat(descriptors, true).reshape(1, (int)features.keypoints.size());
}
}
#ifndef ANDROID