-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcar_detector.py
More file actions
33 lines (23 loc) · 757 Bytes
/
car_detector.py
File metadata and controls
33 lines (23 loc) · 757 Bytes
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
# -*- coding: utf-8 -*-
import cv2
print(cv2.__version__)
cascade_src = 'cars.xml'
#video_src = 'traffic.mp4'
video_src = 'dataset/video1.avi'
#video_src = 'dataset/video2.avi'
cap = cv2.VideoCapture(video_src)
car_cascade = cv2.CascadeClassifier(cascade_src)
while True:
ret, img = cap.read()
if (type(img) == type(None)):
break
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cars = car_cascade.detectMultiScale(gray, 1.1, 1)
for (x,y,w,h) in cars:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
cv2.putText(img,'a car',(x, y),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),1)
cv2.imshow('video', img)
if cv2.waitKey(33) == 27:
print("END")
break
cv2.destroyAllWindows()