forked from sthanhng/yoloface
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTracking.py
55 lines (38 loc) · 1.6 KB
/
Tracking.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
import numpy as np
class Tracking:
def __init__(self):
self.boxes = list()
self.numbers = list()
self.face_num = 0
def update(self, boxes: list):
previous_boxes = self.boxes
previous_numbers = self.numbers
self.boxes = boxes
if len(boxes) == 0:
return []
if len(previous_boxes) == 0:
self.numbers = np.zeros(len(boxes))
self.boxes = boxes
for i, box in enumerate(boxes):
self.face_num += 1
self.numbers[i] = self.face_num
return self.numbers
self.numbers = 2* np.ones(len(boxes))
IOUs = np.zeros((len(previous_boxes), len(boxes)))
for i, previous_box in enumerate(previous_boxes):
IOUs[i] = [box.IOU(previous_box) for box in boxes]
if len(boxes) >= len(previous_boxes):
for i, previous_box in enumerate(previous_boxes):
self.numbers[np.argmax(IOUs[i])] = previous_numbers[i]
for i, number in enumerate(self.numbers):
if number == 2:
self.face_num += 1
self.numbers[i] = self.face_num
else:
for i, box in enumerate(boxes):
self.numbers[i] = previous_numbers[np.argmax(IOUs[:, i])]
for i, number in enumerate(self.numbers):
if number == 2:
self.face_num += 1
self.numbers[i] = self.face_num
return self.numbers