1. 程式人生 > >python opencv SIFT,獲取特徵點的座標位置

python opencv SIFT,獲取特徵點的座標位置

參考地址:https://docs.opencv.org/3.4/d2/d29/classcv_1_1KeyPoint.html

測試程式碼:

 

import cv2  
import numpy as np  
  
img = cv2.imread('4.jpg',cv2.IMREAD_COLOR)  
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  
# cv2.imshow('origin',img)
  
#SIFT  
detector = cv2.xfeatures2d.SIFT_create()
keypoints = detector.detect(gray,None)  
cv2.drawKeypoints(gray,keypoints,img)  

points2f 
= cv2.KeyPoint_convert(keypoints) #將KeyPoint格式資料中的xy座標提取出來。 print(keypoints) print(points2f) cv2.imshow('test',img) cv2.waitKey(0) cv2.destroyAllWindows()

 

測試效果: