您有兩種方法可以檢測圖像選定部分的特徵。
方法1:
通過選擇ROI。這種方法的缺點是計算出的特徵點將具有ROI的座標。例如,如果您的圖像尺寸爲width = 400, height = 400
,則選擇帶模糊的ROI x=0, y=0, width=100, height=100
,關鍵點將根據ROI模糊具有座標。您必須手動將它們映射回原始圖像大小。
img = cv2.imread("image.jpg", -1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# select and ROI with user specified dimensions
roi = gray[50:150,50:150]
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(roi)
img=cv2.drawKeypoints(roi,kp,img)
方法2:
提供掩模以SIFT特徵檢測器方法。掩碼必須是單個通道,無符號字符圖像。
img = cv2.imread("image.jpg", -1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# create a mask image filled with zeros, the size of original image
mask = np.zeros(img.shape[:2], dtype=np.uint8)
# draw your selected ROI on the mask image
cv2.rectangle(mask, (50,50), (150,150), (255), thickness = -1)
sift = cv2.xfeatures2d.SIFT_create()
# provide mask to the detect method
kp = sift.detect(gray,mask)
img=cv2.drawKeypoints(gray,kp,img)
我不是球體和篩選的專家,只是裁剪你想要的,你不會做的伎倆的區域? –