Ask Your Question

Revision history [back]

I have change your code a little and with image samples/data/aloeL.jpg results are

OpenCV detectAndCompute :25757

Local detect and afterCompute :25757

#include <limits>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <time.h>

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

FeatureDetector* detector;
DescriptorExtractor* extractor;
Ptr<Feature2D> b;

void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors)
{
    // Compute keypoints for the image.
    if (!image.empty()) {
        b->detect(image, keypoints);
    }

    if( keypoints.empty() )
        return;

    // Compute descriptors for the image.
    b->compute(image, keypoints, descriptors);
}

int main(int argc, char *argv[])
{

    string det_type = "SIFT";
    string des_type = "SIFT";
    string image_file = "f:/lib/opencv/samples/data/aloeL.jpg";
    Mat img = imread(image_file , CV_LOAD_IMAGE_GRAYSCALE );


    b = cv::xfeatures2d::SiftFeatureDetector::create(                                           0, // nFeatures
                                           4, // nOctaveLayers
                                           0.04, // contrastThreshold
                                           10, //edgeThreshold
                                           1.6 //sigma
                                           );


    Mat descriptors;
    vector<KeyPoint> keypoints;
    b->detectAndCompute( img,Mat(), keypoints,descriptors);
    cout << "OpenCV detectAndCompute :"<<keypoints.size()<<"\n";
    keypoints.clear();
    descriptors = Mat();
    compute(img,keypoints,descriptors);
    cout << "Local detect and afterCompute :"<<keypoints.size()<<"\n";

    return 0;
}