-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect1.py
More file actions
44 lines (27 loc) · 1.08 KB
/
Copy pathdetect1.py
File metadata and controls
44 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import cv2 as cv
import numpy as np
img_query = cv.imread('im1.jpg', cv.IMREAD_GRAYSCALE)
img_train = cv.imread('im1.png', cv.IMREAD_GRAYSCALE)
sift = cv.SIFT_create()
kp_query, des_query = sift.detectAndCompute(img_query, None)
kp_train, des_train = sift.detectAndCompute(img_train, None)
bf = cv.BFMatcher()
matches = bf.knnMatch(des_query, des_train, k=2)
good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
img_matches = cv.drawMatches(img_query, kp_query, img_train, kp_train,
good, None, flags=2)
print(" Attributs du premier point (Query)")
print(f"Coordonnées (x,y): {kp_query[0].pt}")
print(f"Angle: {kp_query[0].angle}")
print(f"Taille (Octave): {kp_query[0].size}")
print("\n Descripteur du premier point")
print(des_query[0])
img_result = cv.drawKeypoints(img_query, kp_query, None,
flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv.imshow('SIFT Keypoints - Query', img_result)
cv.imshow('Mise en correspondance SIFT', img_matches)
cv.waitKey(0)
cv.destroyAllWindows()