-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
113 lines (92 loc) · 3.31 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import tkinter as jra
import cv2
# from PIL import ImageTk
import os
def chuongTrinhNhanDienXe(text):
orb = cv2.ORB_create(nfeatures=1000)
path = "bienbao/"+text
listAnh = []
listNameAnh = []
myList = os.listdir(path)
for name in myList:
imgNow = cv2.imread(f'{path}/{name}', 0)
listAnh.append(imgNow)
listNameAnh.append(os.path.splitext(name)[0])
print(listNameAnh)
def timDacDiem(listAnh):
NhanDang = []
for anh in listAnh:
diemKhac, dinhDanh = orb.detectAndCompute(anh, None)
NhanDang.append(dinhDanh)
return NhanDang
def timID(live, NhanDang, phucTap):
diemKhac2, dinhDanh2 = orb.detectAndCompute(live, None)
bf = cv2.BFMatcher()
listGiong = []
ketLuan = -1
try:
for des in NhanDang:
matches = bf.knnMatch(des, dinhDanh2, k=2) # 2 value can compare on
good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
listGiong.append(len(good))
except:
pass
if len(listGiong) != 0:
if (max(listGiong)) > phucTap:
ketLuan = listGiong.index(max(listGiong))
return ketLuan
Nhandang = timDacDiem(listAnh)
print(len(Nhandang))
quay = cv2.VideoCapture(0)
while True:
success, live = quay.read()
liveMauSac = live.copy()
live = cv2.cvtColor(live, cv2.COLOR_BGR2GRAY)
tenCuaAnh = timID(live, Nhandang, 10)
if id != -1:
cv2.putText(liveMauSac, listNameAnh[tenCuaAnh], (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255), 1)
ten="Phan Mem Nhan Dien Bien Bao "+ text
cv2.imshow(ten, liveMauSac)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
class Application(jra.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master.title("Viet Nam Traffic Signs Detector")
self.master.minsize(500, 150)
self.khoiDong = jra.Button(self)
self.khoiDong["text"] = "Biển Báo Chỉ Dẫn"
self.khoiDong["command"] = self.PressCheck2
self.khoiDong.pack()
self.khac = jra.Button(self)
self.khac["text"] = "Biển Báo Lệnh"
self.khac["command"] = self.PressCheck3
self.khac.pack()
self.khac1 = jra.Button(self)
self.khac1["text"] = "Biển Báo Cấm"
self.khac1["command"] = self.PressCheck1
self.khac1.pack()
self.khac2 = jra.Button(self)
self.khac2["text"] = "Biển Báo Nguy Hiểm"
self.khac2["command"] = self.PressCheck4
self.khac2.pack()
# self.text = jra.(self)
# self.text["text"] = "Biển Báo Nguy Hiểm"
# self.text.pack()
self.quit = jra.Button(self, text="QUIT", command=root.destroy)
self.quit.pack()
self.pack()
self.mainloop()
def PressCheck2(self, event=None):
chuongTrinhNhanDienXe('chiDan')
def PressCheck3(self, event=None):
chuongTrinhNhanDienXe('lenh')
def PressCheck1(self, event=None):
chuongTrinhNhanDienXe('cam')
def PressCheck4(self, event=None):
chuongTrinhNhanDienXe('nguyHiem')
root = jra.Tk()
app = Application(master=root)