-
Notifications
You must be signed in to change notification settings - Fork 38
/
main_trax.py
executable file
·42 lines (35 loc) · 1.12 KB
/
main_trax.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
#!/usr/bin/env python3
from tracking.three_stage_tracker import ThreeStageTracker
import sys
import cv2
import PIL
import numpy as np
import vot_helper
class SiamRCNN:
def __init__(self, image, region):
sp = __file__.split("/")
ckpt = "/".join(sp[:-1]) + "/train_log/hard_mining3/model-1360500"
self._tracker = ThreeStageTracker(model="checkpoint:" + ckpt)
x, y, w, h = region
box = np.array([x, y, w, h])
self._tracker.init(image, box)
def track(self, image):
new_box, score = self._tracker.update(image, use_confidences=True)
x, y, w, h = new_box
print(new_box, score)
rect = vot_helper.Rectangle(x, y, w, h)
return rect, score
handle = vot_helper.VOT("rectangle")
selection = handle.region()
imagefile = handle.frame()
if not imagefile:
sys.exit(0)
image = np.array(PIL.Image.open(imagefile))
tracker = SiamRCNN(image, selection)
while True:
imagefile = handle.frame()
if not imagefile:
break
image = np.array(PIL.Image.open(imagefile))
region, confidence = tracker.track(image)
handle.report(region, confidence)