From 22675373c93d4ec5408369f7d057b987df27b5d7 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sat, 1 Feb 2025 00:54:11 +0800 Subject: [PATCH] update, --- .../task1/_lab/objdetect/main.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 vinniesniper-54816/task1/_lab/objdetect/main.py diff --git a/vinniesniper-54816/task1/_lab/objdetect/main.py b/vinniesniper-54816/task1/_lab/objdetect/main.py new file mode 100644 index 00000000..a017df7d --- /dev/null +++ b/vinniesniper-54816/task1/_lab/objdetect/main.py @@ -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()