-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (41 loc) · 1.33 KB
/
main.py
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
45
46
47
48
49
50
51
52
53
54
55
56
import sys
import cv2
import numpy as np
from matplotlib import pyplot
query = cv2.imread("1.png", 0)
train = cv2.imread("2.png", 0)
def analyze(query, train):
orb = cv2.ORB_create()
# find key points
x1, y1 = orb.detectAndCompute(query, None)
x2, y2 = orb.detectAndCompute(train, None)
# measure distances, verify accuracy
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck = True)
keyf = sorted(bf.match(y1, y2), key = lambda x: x.distance)
final = cv2.drawMatches(query, x1, train, x2, keyf[:10], None, flags=2)
pyplot.imshow(final)
pyplot.draw()
pyplot.pause(0.01)
if not pyplot.get_fignums():
pyplot.show()
if __name__ == "__main__":
mode = input("Mode (image/video): ")
if mode == "video":
video = input("Video (query): ")
model = input("Image (model): ")
cap = cv2.VideoCapture(video)
model = cv2.imread(model, 0)
while True:
ret, frame = cap.read()
analyze(frame, model)
cv2.waitKey(1000)
cap.release()
elif mode == "image":
img1 = input("Image 1 (query): ")
img2 = input("Image 2 (model): ")
query = cv2.imread(img1, 0)
train = cv2.imread(img2, 0)
analyze(query, train)
else:
print("No valid option selected.")
sys.exit()