Ask Your Question
0

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

asked 2015-06-25 06:20:15 -0600

neouyghur gravatar image

updated 2015-06-25 11:03:46 -0600

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;
}
edit retag flag offensive close merge delete

Comments

Which code is it? Is it this ?

LBerger gravatar imageLBerger ( 2015-06-25 08:09:19 -0600 )edit

no, if you want I can paste my code.

neouyghur gravatar imageneouyghur ( 2015-06-25 10:58:32 -0600 )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 ( 2015-06-25 12:54:03 -0600 )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 ( 2015-06-26 02:40:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-06-26 06:42:21 -0600

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;
}
edit flag offensive delete link more

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 ( 2015-07-01 10:43:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-25 06:20:15 -0600

Seen: 639 times

Last updated: Jul 01 '15