Search code examples
pythonmatrixmatchingfeature-extraction

Python - Matching keypoints using feature vectors


I'm trying to match keypoints of 2 meshes using their feature vectors and the euclidean distance as a similarity measure,

What I tried and here is a simple instance of it, I made an example of the main data:

a = [0,1,4,6]
    fv_a = [[2.1,4],
            [0.7,3.1],
            [2.23,6],
            [0,1.11]]
    b = [1,3,0,4]
    fv_b = [[0.7,3.1],
            [4.1,3.3],
            [2.1,4],
            [2.23,6]]
    fv_a = (fv_a - np.min(fv_a)) / np.ptp(fv_a)
    fv_b = (fv_b - np.min(fv_b)) / np.ptp(fv_b)
    distances = scipy.spatial.distance.cdist(fv_a,fv_b)
    print(distances)
    # print(np.amax(distances,1))
    # print(np.argmax(distances,1))
    matched = np.argmax(distances,1)
    print(matched)
    for i,j in enumerate(matched):
        print(i, "linked to : ",j)
        print("point in a",a[i]," is matched to: ",b[j])

So the point is that for each point in a I have a feature vector for it represented in fv_a and I'm trying to match it with b

but the results are like this:

 [0.1329895  0.52549136 0.18161024 0.51302967]
 [0.6614612  0.57648771 0.39237617 0.08298742]
 [0.26783019 0.71056665 0.5111808  0.86461593]]
[0 1 0 3]
0 linked to :  0
point in a 0  is matched to:  1
1 linked to :  1
point in a 1  is matched to:  3
2 linked to :  0
point in a 4  is matched to:  1
3 linked to :  3
point in a 6  is matched to:  4

and this is not correct, since 0 should match 0, 1 should match 1, etc..

What am I doing wrong, please?

and yes, I'm trying to do one-to-one-matching. Any recommendations kindly?


Solution

  • Using Scikit Library Did the trick.

    This function let me get what I need :)

    from skimage.feature import match_descriptors