-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTracker.py
63 lines (37 loc) · 1.33 KB
/
Tracker.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
from cv2 import cv2
# img_file = 'car3_image.jpg'
video = cv2.VideoCapture('ride_video.mp4')
car_tracker_file = 'cars.xml'
pedestrian_tracker_file = 'haarcascade_fullbody.xml'
car_tracker = cv2.CascadeClassifier(car_tracker_file)
pedestrian_tracker = cv2.CascadeClassifier(pedestrian_tracker_file)
while True:
(read_successfull, frame) = video.read()
if read_successfull:
grayscaled_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
else:
break
cars = car_tracker.detectMultiScale(grayscaled_frame)
pedestrian = pedestrian_tracker.detectMultiScale(grayscaled_frame)
for (x, y, w, h) in cars:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
for (x, y, w, h) in pedestrian:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 255), 2)
cv2.imshow('Car & Pedestrian Tracker', frame)
key = cv2.waitKey(1)
if key == 81 or key == 113:
break
video.release()
cv2.destroyAllWindows()
print("Completed")
'''
img = cv2.imread(img_file)
black_n_white = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
car_tracker = cv2.CascadeClassifier(classifier_file)
cars = car_tracker.detectMultiScale(black_n_white)
print(cars)
for (x, y, w, h) in cars:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.imshow('Car & Pedestrian Detector', img)
cv2.waitKey()
'''