-
Notifications
You must be signed in to change notification settings - Fork 58
/
demo.py
60 lines (45 loc) · 1.55 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from tracker import Tracker
from detector import Detector
import imutils, argparse, cv2
import os
from glob import glob
def track_images(img_dir):
tracker = Tracker(model='yolox-s', ckpt='weights/yolox_s.pth.tar',filter_class=['truck','person','car'])
imgs = glob(os.path.join(img_dir,'*.png')) + glob(os.path.join(img_dir,'*.jpg')) + glob(os.path.join(img_dir,'*.jpeg'))
for path in imgs:
im = cv2.imread(path)
im = imutils.resize(im, height=400)
image,_ = tracker.update(im)
#image = imutils.resize(image, height=500)
cv2.imshow('demo', image)
cv2.waitKey(1)
if cv2.getWindowProperty('demo', cv2.WND_PROP_AUTOSIZE) < 1:
break
cv2.destroyAllWindows()
def track_cap(file):
cap = cv2.VideoCapture(file)
tracker = Tracker()
a = 0
while True:
_, im = cap.read()
if im is None:
break
a += 1
if a%10!=0:
continue
im = imutils.resize(im, height=500)
image,_ = tracker.update(im)
cv2.imshow('demo', image)
cv2.waitKey(1)
if cv2.getWindowProperty('demo', cv2.WND_PROP_AUTOSIZE) < 1:
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
parser = argparse.ArgumentParser("YOLOX-Tracker Demo!")
parser.add_argument('-p', "--path", type=str, default='test.mp4', help="choose a video")
args = parser.parse_args()
if os.path.isfile(args.path):
track_cap(args.path)
else:
track_images(args.path)