-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.py
112 lines (90 loc) · 3.08 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'''
Functions for keeping track of detected peoples in a video.
'''
import cv2
from util.logger import get_logger
logger = get_logger()
def csrt_create(bounding_box, frame):
"""
Creates an OpenCV CSRT Tracker object.
:param bounding_box: the location of the object
:param frame: frame that the object was detected on
:return: the tracker
"""
tracker = cv2.TrackerCSRT_create()
tracker.init(frame, tuple(bounding_box))
return tracker
def kcf_create(bounding_box, frame):
"""
Creates an OpenCV KCF Tracker object.
:param bounding_box: the location of the object
:param frame: frame that the object was detected on
:return: the tracker
"""
tracker = cv2.TrackerKCF_create()
tracker.init(frame, tuple(bounding_box))
return tracker
# ###### untested trackers : ############
def MEDIANFLOW_create(bounding_box, frame):
"""
Creates an OpenCV MEDIANFLOW Tracker object.
:param bounding_box: the location of the object
:param frame: frame that the object was detected on
:return: the tracker
"""
tracker = cv2.TrackerMedianFlow_create()
tracker.init(frame, tuple(bounding_box))
return tracker
def GOTURN_create(bounding_box, frame):
"""
Creates an OpenCV GOTURN Tracker object.
:param bounding_box: the location of the object
:param frame: frame that the object was detected on
:return: the tracker
"""
tracker = cv2.TrackerGOTURN_create()
tracker.init(frame, tuple(bounding_box))
return tracker
def MOSSE_create(bounding_box, frame):
"""
Creates an OpenCV MOSSE Tracker object
:param bounding_box: the location of the object
:param frame: frame that the object was detected on
:return: the tracker
"""
tracker = cv2.TrackerMOSSE_create()
tracker.init(frame, tuple(bounding_box))
return tracker
def TLD_create(bounding_box, frame):
"""
Creates an OpenCV TLD Tracker object.
:param bounding_box: the location of the object
:param frame: frame that the object was detected on
:return: the tracker
"""
tracker = cv2.TrackerTLD_create()
tracker.init(frame, tuple(bounding_box))
return tracker
def get_tracker(algorithm, bounding_box, frame):
"""
Fetches a tracker object based on the algorithm specified.
:param algorithm: the algorithm for the tracker.
:param bounding_box: the location of the object.
:param frame: frame that the object was detected on
:return: the tracker.
"""
if algorithm == 'csrt':
return csrt_create(bounding_box, frame)
elif algorithm == 'kcf':
return kcf_create(bounding_box, frame)
elif algorithm == 'medianflow':
return MEDIANFLOW_create(bounding_box, frame)
elif algorithm == 'goturn':
return GOTURN_create(bounding_box, frame)
elif algorithm == 'mosse':
return MOSSE_create(bounding_box, frame)
elif algorithm == 'tld':
return TLD_create(bounding_box, frame)
logger.error('Invalid tracking algorithm specified (options: csrt, kcf)', extra={
'meta': {'cat': 'TRACKER_CREATE'},
})