-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathapp.py
36 lines (28 loc) · 1.07 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
import cv2
cars_cascade = cv2.CascadeClassifier('haarcascade_car.xml')
body_cascade = cv2.CascadeClassifier('fullbody.xml')
def detect_cars_and_pedestrain(frame):
cars = cars_cascade.detectMultiScale(frame, 1.15, 4)
pedistrain = body_cascade.detectMultiScale(frame, 1.15, 4)
for (x, y, w, h) in cars:
cv2.rectangle(frame, (x+1, y+1), (x+w,y+h), color=(255, 0, 0), thickness=2)
cv2.rectangle(frame, (x, y), (x+w, y+h), color=(0, 255, 0), thickness=2)
for(x, y, w, h) in pedistrain:
cv2.rectangle(frame, (x, y), (x+w, y+h), color=(0, 255, 255), thickness=2)
return frame
def Simulator():
CarVideo = cv2.VideoCapture('cars.mp4')
while CarVideo.isOpened():
ret, frame = CarVideo.read()
controlkey = cv2.waitKey(1)
if ret:
cars_frame = detect_cars_and_pedestrain(frame)
cv2.imshow('frame', cars_frame)
else:
break
if controlkey == ord('q'):
break
CarVideo.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
Simulator()