First time here? Check out the FAQ!

Ask Your Question
0

why opencv 2.4.10 linux, windows version SIFT returns different features?

asked Jun 25 '15

neouyghur gravatar image

updated Jun 25 '15

We have implemented the same code on Linux and Windows platform, but we have got different results. Size and detail of features are different. In Linux for same image we got 187 features but 216 in Windows, and we can't find similar features.

Could anyone encounter this problem? Thank you.

my code:

#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/highgui/highgui.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/legacy/legacy.hpp>

using namespace std;
using namespace cv;

FeatureDetector* detector;
DescriptorExtractor* extractor;

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

    if( keypoints.empty() )
        return;

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

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

    string det_type = "SIFT";
    string des_type = "SIFT";
    string image_file = "test.jpg";
   Mat img = imread(image_file , CV_LOAD_IMAGE_GRAYSCALE );
    initModule_nonfree();
    detector = new SiftFeatureDetector(
                                           0, // nFeatures
                                           4, // nOctaveLayers
                                           0.04, // contrastThreshold
                                           10, //edgeThreshold
                                           1.6 //sigma
                                           );

    extractor = new SiftDescriptorExtractor();

    Mat descriptors;
    vector<KeyPoint> keypoints;
    compute( img, keypoints, descriptors);

    return 0;
}
Preview: (hide)

Comments

Which code is it? Is it this ?

LBerger gravatar imageLBerger (Jun 25 '15)edit

no, if you want I can paste my code.

neouyghur gravatar imageneouyghur (Jun 25 '15)edit

It's not opencv 3.0. I cannot test. May be you can check if all versions are similar using cv::getBuildInformation().c_str()

LBerger gravatar imageLBerger (Jun 25 '15)edit

could you check opencv3.0 version for me. Thank you. Because our research platform is linux, but development platform is windows.

neouyghur gravatar imageneouyghur (Jun 26 '15)edit

1 answer

Sort by » oldest newest most voted
2

answered Jun 26 '15

LBerger gravatar image

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;
}
Preview: (hide)

Comments

Thank you for offering code. After using my original code and your code for testing 2.4.10 and 3.0 version on Linux and Windows I found they returned same results. Maybe there is a configuration problem in my original windows platform. I will find it then report it here soon.

neouyghur gravatar imageneouyghur (Jul 1 '15)edit

Question Tools

1 follower

Stats

Asked: Jun 25 '15

Seen: 663 times

Last updated: Jul 01 '15