diff --git a/5/1.py b/5/1.py new file mode 100644 index 0000000..02c3e43 --- /dev/null +++ b/5/1.py @@ -0,0 +1,13 @@ +import cv2 as cv + +image = cv.imread("images/lena.jpg") + +sift = cv.SIFT_create() # type: ignore + +keypoints, descriptors = sift.detectAndCompute(image, None) + +image_with_keypoints = cv.drawKeypoints(image, keypoints, None) # type: ignore + +cv.imshow("SIFT Keypoints", image_with_keypoints) +cv.waitKey(0) +cv.destroyAllWindows() diff --git a/5/2.py b/5/2.py new file mode 100644 index 0000000..8227453 --- /dev/null +++ b/5/2.py @@ -0,0 +1,27 @@ +import cv2 as cv + +big = cv.imread("images/big.jpg") +small = cv.imread("images/small.jpg") +cv.imshow("big", big) +cv.waitKey(0) +cv.destroyAllWindows() +cv.imshow("small", small) +cv.waitKey(0) +cv.destroyAllWindows() + +sift = cv.SIFT_create() # type: ignore + +kp1, des1 = sift.detectAndCompute(big, None) +kp2, des2 = sift.detectAndCompute(small, None) + +bf = cv.DescriptorMatcher_create(cv.DescriptorMatcher_BRUTEFORCE) # type: ignore + +matches = bf.match(des1, des2) + +matches = sorted(matches, key=lambda x: x.distance) + +result = cv.drawMatches(big, kp1, small, kp2, matches[:15], None) # type: ignore + +cv.imshow("-match", result) +cv.waitKey(0) +cv.destroyAllWindows() diff --git a/images/big.jpg b/images/big.jpg new file mode 100644 index 0000000..e0dfff0 Binary files /dev/null and b/images/big.jpg differ diff --git a/images/small.jpg b/images/small.jpg new file mode 100644 index 0000000..22cc218 Binary files /dev/null and b/images/small.jpg differ