Application OpenCV and Python python- be achieved SIFT algorithm

The picture shows the following testing q and h, respectively, based authentication BFmatcher, FlannBasedMatcher like SIFT Algorithm

code show as below:

Import numpy AS NP
 Import CV2
 from matplotlib Import pyplot AS PLT 


imgname1 = ' G: /q.jpg ' 
imgname2 = ' G: /h.jpg ' 

SIFT = cv2.xfeatures2d.SIFT_create () 
IMG1 = cv2.imread (imgname1) 
Gray1 cv2.cvtColor = (IMG1, cv2.COLOR_BGR2GRAY) # gradation processing images 
KP1, DES1 = sift.detectAndCompute (IMG1, None)    # des descriptor is 

IMG2 = cv2.imread (imgname2) 

GRAY2 = cv2.cvtColor (IMG2, CV2 .COLOR_BGR2GRAY) # gradation processed image
KP2, DES2 = sift.detectAndCompute (IMG2, None)   # des is the descriptor 

# hmerge np.hstack = ((Gray1, GRAY2)) # splicing horizontal 
# cv2.imshow ( "Gray", hmerge) # tiled display as Gray 
# cv2.waitKey (0) 

# img3 = cv2.drawKeypoints (IMG1, KP1, IMG1, Color = (255,0,255)) # draw feature points, and displayed as red circle 
# img4 = cv2.drawKeypoints (IMG2, KP2, IMG2 , color = (255,0,255)) # draw feature points, and displayed as red circle 

# hmerge np.hstack = ((img3, img4)) # splicing horizontal 
# cv2.imshow ( "point", hmerge) # tiled display of Gray 
# cv2.waitKey (0) 

# BFMatcher matching solution 
BF = cv2.BFMatcher () 
The matches = bf.knnMatch (DES1, DES2, K = 2 )
 # adjust the ratio
good = []
for m,n in matches:
    if m.distance < 0.75*n.distance:
        good.append([m])

img5 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,None,flags=2)

cv2.imshow("BFmatch", img5)
cv2.waitKey(0)
cv2.destroyAllWindows()

Results are as follows:

 

Guess you like

Origin www.cnblogs.com/zhouxuejia/p/10990471.html