-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstop.py
27 lines (24 loc) · 810 Bytes
/
stop.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
import cv2
class Stop:
def __init__(self):
self.cas = cv2.CascadeClassifier('stopsign_classifier.xml')
def detect(self, frame):
x = 0
w = 0
frame = cv2.resize(frame, (640, 480))
# cv2.imshow('fra',frame)
frame2 = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# cv2.imshow('fra',frame2)
boxes = self.cas.detectMultiScale(frame2, 1.3, 5)
for (x, y, w, h) in boxes:
frame = cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
if x == 0:
return frame, -1
elif (x+w) > 320:
# print((x+w)/2)
return frame, 0
elif (x+w) <= 320:
# print((x+w)/2)
return frame, 1
else:
return frame, -1