How to use keypoints from .txt file (or another structure) in opencv?

asked 2016-06-06 06:46:02 -0600

lovaj gravatar image

I'm using the Fast SIFT Image Features Library, which is incredibly faster than the OpenCV implementation (approx 0.01 sec for keypoints and descriptors computations!).

However, the resulting keypoints are written in this form:

#keys #key_dimension
(for #keys) [x y scale orientation (for #key_dimension)[value] ]

How can I use them in OpenCV?

For example:

872 128
138.423 44.7441 17.4935 0.159259
7 0 0 0 0 0 0 0 116 1 0 0 3 4 13 66 
13 0 0 11 82 62 27 31 2 2 1 7 41 43 16 7 
38 2 0 0 0 0 0 0 150 14 3 2 14 9 1 43 
44 4 7 35 150 81 3 19 14 17 7 17 44 33 4 2 
76 1 0 0 0 0 0 3 150 42 21 24 11 8 1 25 
21 14 81 150 83 45 1 2 38 6 38 78 31 19 0 15 
99 4 0 0 0 0 0 11 150 29 9 6 14 35 10 75 
4 2 16 44 83 150 7 7 74 12 10 20 19 41 5 27 

129.296 154.326 14.76 0.11844
2 4 3 37 68 27 4 0 23 10 6 7 8 30 26 14 
114 2 0 2 14 12 15 78 6 0 0 5 104 61 10 8 
3 4 6 26 90 105 14 2 44 27 18 26 26 18 10 4 
119 62 7 10 18 1 0 15 5 4 1 11 119 19 0 1 
0 0 115 86 38 40 5 0 78 8 38 85 36 11 3 28 
119 14 1 3 8 15 13 119 3 1 0 13 119 36 7 8 
0 0 19 16 30 100 26 0 119 9 12 13 10 26 14 47 
119 17 4 9 28 12 8 90 0 0 0 47 119 19 2 1

Notice that this is the output by default, while I can use it how I please, in fact the example above is produced by the following code:

Keypoint keypts;
...
key = keypts;
while(key) {
    cout << key->row << " " << key->col << " " << key->scale << " " << key->ori << endl;

    for(int i = 0; i < 128; ++i) {
        int intdesc = (int)(key->descrip[i]*512.0f);
        assert( intdesc >= 0 );

        if( intdesc > 255 )
            intdesc = 255;
        cout << intdesc << " ";
        if( (i&15)==15 )
            cout << endl;
    }
    cout << endl;
    key = key->next;
}

Where:

typedef struct KeypointSt {
    float row, col;             // Subpixel location of keypoint.
    float scale, ori;           // Scale and orientation (range [-PI,PI])
    float descrip[128];     // Vector of descriptor values
    struct KeypointSt *next;    // Pointer to next keypoint in list.
} *Keypoint;
edit retag flag offensive close merge delete