-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrackerBase.py
114 lines (90 loc) · 3.44 KB
/
TrackerBase.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
111
112
113
114
"""
The ahstract base class for all tracking algorithms.
Author: Travis Dick ([email protected])
"""
import numpy as np
class TrackerBase:
""" The base class for all tracking algorithms.
This class serves two purposes. First, it demonstrates
the minimal interface expected by a tracking algorithm.
Second, it implements various algorithm-independent
converstions - mainly convenience functions for working
with rectangles instead of arbitrary quadrilaterals.
"""
def set_region(self, corners):
""" Sets the tracker's current state.
Parameters:
-----------
corners : (2,4) numpy array
An array where each column is one corner of the target region.
They should come in the following order:
corners[:,0] = template upper left corner
corners[:,1] = template upper right corner
corners[:,2] = template lower right corner
corners[:,3] = template lower left corner
See Also:
---------
set_region_with_rectangle
"""
raise NotImplementedError()
def set_region_with_rectangle(self, ul, lr):
""" Sets the tracker's current state.
Parameters:
-----------
ul : (real, real)
A tuple representing the pixel coordinates of the upper left
corner of the target region
lr : (real, real)
A tuple representing the pixel coordinates of the lower right
corner of the target region
See Also:
---------
set_region
"""
self.set_region(_rectangle_to_region(ul,lr))
def initialize(self, img, region):
""" Initializes the tracker.
This function indicates to the tracking algorithm what
the target object is.
Parameters:
-----------
img : (n,m) numpy array
The frame containing the image of the target object.
region : (2,4) numpy array
The corners of the target region. See set_region for details
See Also:
---------
initialize_with_rectangle
"""
raise NotImplementedError()
def initialize_with_rectangle(self, img, ul, lr):
""" Initializes the tracker.
Same as initialize except the target region is specified
using the upper left and lower right corners only.
See Also:
---------
initialize
"""
self.initialize(img, _rectangle_to_region(ul,lr))
def update(self, img):
""" Updates the tracker state.
This function should be called once for each frame in the video.
Parameters:
-----------
img : (n,m) numpy array
The most recent image in the video sequence.
"""
raise NotImplementedError()
def is_initialized(self):
""" Returns whether the tracker is initialized yet or not. """
raise NotImplementedError()
def get_region(self):
""" Returns the four corners of the target region. See set_region
for more information on the format.
See Also:
---------
set_region
"""
raise NotImplementedError()
def _rectangle_to_region(ul, lr):
return np.array([ul, [lr[0],ul[1]], lr, [ul[0],lr[1]]]).T