Ask Your Question
1

SIFT descriptor for custom keypoints

asked 2017-01-31 05:37:49 -0600

mwlodarczyk gravatar image

Hi,

I want to extract sift features for custom defined keypoints. There is a class cv::KeyPoint that can be used to create custom points. However, I am not sure how to decode the proper information in 'size' and 'octave' parameters. I want to extract descriptors for various scales, e.g.: 3, 5, 7. What values should I use for 'size' and 'octave'? Any ideas?

edit retag flag offensive close merge delete

Comments

Extracting SIFT (or other detector) parameters from custom keypoints interests me too...

kbarni gravatar imagekbarni ( 2017-02-03 10:21:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-02-03 14:55:47 -0600

LBerger gravatar image

I think you don't need octave parameters when you want to compute SURF descriptor. You need only location (point2f) and size (float) octave is used when you want to detect point. SURF descriptors are computed here

I have tested this method using this program

    Mat image1 = imread("F:/lib/opencv/samples/data/lena.jpg",IMREAD_COLOR);
    Ptr<Feature2D> bsurf = cv::xfeatures2d::SurfFeatureDetector::create(400);
    std::vector< KeyPoint > keypoints_object;
    Mat descriptors_object;
    bsurf->detect(image1, keypoints_object);
    bsurf->compute(image1, keypoints_object, descriptors_object);
    cout << "*************** SURF REF ********************\n";
    cout << keypoints_object[0].size << "\t" << keypoints_object[0].angle << "\t" << keypoints_object[0].response << "\t" << keypoints_object[0].octave;
    cout<< "\t" << descriptors_object.row(0) << "\n";
    cout << "SURF TEST ********************\n";

    for (int i = 0; i < 3; i++)
    {
        Ptr<Feature2D> bsurf2 = cv::xfeatures2d::SurfFeatureDetector::create(400);
        std::vector<KeyPoint> testKey;
        KeyPoint pTest{ keypoints_object[0].pt,i*1.5F+keypoints_object[0].size,0.0F,0.0F,0,-1 };
        testKey.push_back(pTest);
        bsurf2->compute(image1, testKey, descriptors_object);
        cout << testKey[0].size << "\t" << testKey[0].angle << "\t" << testKey[0].response << "\t" << testKey[0].octave << "\t" << descriptors_object << "\n";

    }

When angle varying descriptors change. same angle = same descriptor even if octave or response are different

For SIFT descriptors it is not so easy. You have to know octave and layer and xi quantity. It is computed here

Quantity xi is defined here see section 4 of Lowe's paper

program to test is :

    cout << "*************** SIFT REF********************\n";
    keypoints_object.clear();
    Ptr<Feature2D> bsift = cv::xfeatures2d::SiftFeatureDetector::create(1);
    bsift->detect(image1, keypoints_object);
    bsift->compute(image1, keypoints_object, descriptors_object);
    cout << keypoints_object[0].size << "\t" <<keypoints_object[0].angle << "\t" << keypoints_object[0].response << "\t" << keypoints_object[0].octave << "\n";
    cout<< descriptors_object << "\n";
    cout << "SIFT TEST ********************\n";
    float xi=-0.494;
    for (int i = 0; i < 3; i++)
    {
        Ptr<Feature2D> bsift2 = cv::xfeatures2d::SiftFeatureDetector::create(1);
        std::vector<KeyPoint> testKey;
        int octave=-1;
        int layer=3;
        KeyPoint pTest={keypoints_object[0].pt, keypoints_object[0].size+i*10,keypoints_object[0].angle,0,0,-1 };
        pTest.octave= octave + (layer << 8) +(cvRound((xi + 0.5) * 255) << 16);
        testKey.push_back(pTest);
        bsift2->compute(image1, testKey, descriptors_object);
        cout << testKey[0].size << "\t" << testKey[0].angle << "\t" << testKey[0].response << "\t" << keypoints_object[0].octave << "\n" << descriptors_object << "\n";

    }

I think that it is necessary to read lowe's paper...

edit flag offensive delete link more

Comments

Hi @LBerger. Thank you for your reply. I will try to play with your code and study Lowe's paper one more time. Basically, what I need is a function that will calculate the octave. The input from my side is: x, y, scale.

mwlodarczyk gravatar imagemwlodarczyk ( 2017-02-07 09:38:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-31 05:37:49 -0600

Seen: 983 times

Last updated: Feb 03 '17