简体   繁体   中英

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

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM