Ask Your Question
0

SIFT Feature matches coordinates

asked 2017-10-06 08:26:27 -0600

everwill02 gravatar image

updated 2017-10-06 08:28:30 -0600

Hello, I want to print the detect features keypoints with the FLANN based Matcher Algorithm : http://docs.opencv.org/trunk/dc/dc3/t.... The search works fine and show as the tutorial the keypoints in red(all) and green(good). I want only print the coordinates(x,y) named here ‘kp2’ of the second image(scene) but it doesn’t work. Here is my code :

import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('img1.jpg',0)          # queryImage
img2 = cv2.imread('img2.jpg',0) # trainImage
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)
# FLANN parameters
FLANN_INDEX_KDTREE = 1
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50)   # or pass empty dictionary
flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(des1,des2,k=2)
# Need to draw only good matches, so create a mask
matchesMask = [[0,0] for i in range(len(matches))]

# ratio test as per Lowe's paper
for i,(m,n) in enumerate(matches):
    if m.distance < 0.7*n.distance:
        matchesMask[i]=[1,0]
        print(i,kp2[i].pt)

draw_params = dict(matchColor = (0,255,0),
                   singlePointColor = (255,0,0),
                   matchesMask = matchesMask,
                   flags = 0)
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,**draw_params)
plt.imshow(img3,),plt.show()

My result :

77 (67.68722534179688, 92.98455047607422)
82 (14.395119667053223, 93.1697998046875)
86 (127.58460235595703, 98.1304931640625)
109 (66.52041625976562, 111.51738739013672)
110 (66.52041625976562, 111.51738739013672)
146 (69.3978500366211, 11.287369728088379)

The number of match keypoints is good but the coordinates are wrong print(i,kp2[i].pt). I checked with the original image. What I did wrong and if yes which lines I have to put to print only the match keypoints coordinates. Thanks for all.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2017-10-06 09:45:26 -0600

everwill02 gravatar image

updated 2017-10-06 09:46:29 -0600

I just find an issue. I change with:

# ratio test as per Lowe's paper
for i,(m,n) in enumerate(matches):
    if m.distance < 0.7*n.distance:
        matchesMask[i]=[1,0]
        good.append(m)


dst_pt = [ kp2[m.trainIdx].pt for m in good ]
print(dst_pt)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-06 08:26:27 -0600

Seen: 2,700 times

Last updated: Oct 06 '17