forked from andrewssobral/simple_vehicle_counting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
39 lines (32 loc) · 1.02 KB
/
demo.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
from __future__ import print_function
import cv2
import analysis
import tracking
import bgs.pbas as pbas
if __name__ == '__main__':
# noinspection PyArgumentList
cap = cv2.VideoCapture('dataset/video.avi')
if not cap.isOpened():
print('Cannot open video!')
exit(1)
# noinspection PyUnresolvedReferences
segmenter = pbas.PixelBasedAdaptiveSegmenter()
# noinspection PyUnresolvedReferences
counter = analysis.VehicleCouting()
# noinspection PyUnresolvedReferences
tracker = tracking.BlobTracking()
while (True):
ret, frame = cap.read()
if not ret:
break
img_mask = segmenter.process(frame)
if img_mask is not None:
img_blob = tracker.process(frame, img_mask)
counter.setInput(img_blob)
counter.setTracks(tracker.getTracks())
counter.process()
cv2.imshow('input', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()