2

What is the right output type of SIFT descriptors on OpenCV?

I am asking this because I know that it is float/double, but when I try to save the descriptors on a file it saves some int values...

My code:

    cv::Mat img;
    std::vector<cv::KeyPoint> imgKeypoints;
    cv::Mat imgDescriptors;
    cv::DescriptorExtractor *extractor;
    cv::FeatureDetector *detector;

    img = cv::imread(this->imageFileName.c_str(), cv::IMREAD_GRAYSCALE);

    detector = new cv::DenseFeatureDetector(15.0, 1, 0.1, 6, 0, true, false);
    extractor = new cv::SIFT(0, 3, 0.04, 10.0, 1.6);

    extractor->compute(this->img, this->imgKeypoints, this->imgDescriptors);

    std::ofstream fout(outputFile.data());
    //I need to save it on this specified format
    for (int i = 0; i < this->imgDescriptors.rows; i++)
    {
        for (int j = 0; j < this->imgDescriptors.cols; j++)
            fout << " " << float(this->imgDescriptors.at<float>(i,j));
    }

The output file comes like this:

0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 2 3 10 13 10 1 1 0 24 5 2 3 5 1 0 5 0 0 0 0 0 0 0 0 3 3 7 4 2 1 2 2 23 13 27 30 35 19 21 35 96 16 15 35 43 12 9 123 0 0 0 0 0 0 0 0 5 1 1 2 2 4 7 7 45 8 27 66 27 17 41 127 57 18 82 100 67 14 16 90 0 0 0 0 0 0 0 0 6 0 1 17 9 1 2 30 143 26 50 168 168 4 5 107 168 58 86 168 74 14 5 54

They are all int values, right? Is it right??? Shouldn't it be float?

Alexis King
  • 43,109
  • 15
  • 131
  • 205
Carlos
  • 49
  • 1
  • 4
  • Yes, it is right. It is float and then scaled by multiplying by 512 - that is why is is integer. – old-ufo Jun 25 '14 at 20:19
  • scaled by multiplying by 512? Why? Didn't get it... Can I save them without this scaled/multiplied? – Carlos Jun 25 '14 at 20:53
  • Wow! I got the answer from another question: http://stackoverflow.com/questions/14911770/how-does-the-siftdescriptorextractor-from-opencv-convert-descriptor-values Thanks anyway. :-) – Carlos Jun 25 '14 at 21:00

1 Answers1

2

Wow! I got the answer from another question: How does the SiftDescriptorExtractor from OpenCV convert descriptor values?

This is because classical SIFT implementations quantize the normalized floating point values into unsigned char integer through a 512 multiplying factor, which is equivalent to consider that any SIFT component varies between [0, 1/2], and thus avoid to loose precision trying to encode the full [0, 1] range.

Sorry for the duplication... =S

eshirima
  • 3,837
  • 5
  • 37
  • 61
Carlos
  • 49
  • 1
  • 4