Avoid duplicated surf extraction step when same parameters are used for detection and descriptors calculation
This commit is contained in:
parent
20af242a03
commit
ee413b8026
@ -79,13 +79,14 @@ class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
|
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:
|
private:
|
||||||
void find(const Mat &image, ImageFeatures &features);
|
void find(const Mat &image, ImageFeatures &features);
|
||||||
|
|
||||||
Ptr<FeatureDetector> detector_;
|
Ptr<FeatureDetector> detector_;
|
||||||
Ptr<DescriptorExtractor> extractor_;
|
Ptr<DescriptorExtractor> extractor_;
|
||||||
|
Ptr<SURF> surf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,8 +293,15 @@ void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features, cons
|
|||||||
SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int num_layers,
|
SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int num_layers,
|
||||||
int num_octaves_descr, int num_layers_descr)
|
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);
|
detector_ = new SurfFeatureDetector(hess_thresh, num_octaves, num_layers);
|
||||||
extractor_ = new SurfDescriptorExtractor(num_octaves_descr, num_layers_descr);
|
extractor_ = new SurfDescriptorExtractor(num_octaves_descr, num_layers_descr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -303,8 +310,17 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
|
|||||||
Mat gray_image;
|
Mat gray_image;
|
||||||
CV_Assert(image.depth() == CV_8U);
|
CV_Assert(image.depth() == CV_8U);
|
||||||
cvtColor(image, gray_image, CV_BGR2GRAY);
|
cvtColor(image, gray_image, CV_BGR2GRAY);
|
||||||
|
if (surf == 0)
|
||||||
|
{
|
||||||
detector_->detect(gray_image, features.keypoints);
|
detector_->detect(gray_image, features.keypoints);
|
||||||
extractor_->compute(gray_image, features.keypoints, features.descriptors);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user