-
Notifications
You must be signed in to change notification settings - Fork 95
/
demo.py
67 lines (51 loc) · 1.88 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
61
62
63
64
65
66
#!/usr/bin/python
import torch
import argparse
import sys
import cv2
import numpy as np
import time
import demo_utils.vot as vot
from demo_utils.siamvggtracker import SiamVGGTracker
# *****************************************
# VOT: Create VOT handle at the beginning
# Then get the initializaton region
# and the first image
# *****************************************
parser = argparse.ArgumentParser(description='PyTorch SiameseX demo')
parser.add_argument('--model', metavar='model', default='SiamFCNext22', type=str,
help='which model to use.')
args = parser.parse_args()
handle = vot.VOT("rectangle")
selection = handle.region()
# Process the first frame
imagefile = handle.frame()
tracker = SiamVGGTracker(args.model, imagefile, selection)
if not imagefile:
sys.exit(0)
toc = 0
while True:
# *****************************************
# VOT: Call frame method to get path of the
# current image frame. If the result is
# null, the sequence is over.
# *****************************************
tic = cv2.getTickCount()
imagefile = handle.frame()
image = cv2.imread(imagefile)
if not imagefile:
break
region, confidence = tracker.track(imagefile)
toc += cv2.getTickCount() - tic
region = vot.Rectangle(region.x, region.y, region.width, region.height)
# *****************************************
# VOT: Report the position of the object
# every frame using report method.
# *****************************************
handle.report(region, confidence)
cv2.rectangle(image, (int(region.x), int(region.y)), (int(region.x + region.width), int(region.y + region.height)), (0, 255, 255), 3)
cv2.imshow('SiameseX', image)
cv2.waitKey(1)
# if cv2.waitKey() == 27:
# break
print('Tracking Speed {:.1f}fps'.format((len(handle) - 1) / (toc / cv2.getTickFrequency())))