update,
This commit is contained in:
27
vinniesniper-54816/task1/_lab/objdetect/main.py
Normal file
27
vinniesniper-54816/task1/_lab/objdetect/main.py
Normal 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()
|
Reference in New Issue
Block a user