This commit is contained in:
louiscklaw
2025-02-01 00:54:11 +08:00
parent 460fc0f81d
commit 22675373c9

View File

@@ -0,0 +1,27 @@
import cv2
import numpy as np
# Load the image
img = cv2.imread("beach.jpg")
# Convert the image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Detect corners using the Harris corner detector
corners = cv2.goodFeaturesToTrack(gray, 100, 0.3, 10)
# Calculate the feature vectors using the SIFT descriptor
sift = cv2.xfeatures2d.SIFT_create()
kp, des = sift.detectAndCompute(gray, None)
# Match the feature vectors using the FLANN matcher
matcher = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_FLANNBASED)
matches = matcher.knnMatch(des, des, k=2)
# Draw the matched keypoints
cv2.drawMatches(img, kp, img, kp, matches, None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
# Display the image
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()