-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrowd.py
39 lines (38 loc) · 1.46 KB
/
crowd.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
from pptracking_util import dist, Arrow, ThicknessSigmoid
import numpy as np
class Crowd:
def __init__(self, people,):
self.people = tuple(people)
def __repr__(self):
return '\n---Crowd---\n人數:{}, ids:{}'.format(len(self.people),[pdata.id for pdata in self.people])
def __hash__(self):
return hash(self.__repr__())
def __eq__(self, other):
for pp_a in self.people:
if pp_a not in other.people:
return False
return True
def size(self):
return len(self.people)
def isSame(self, crowd):
if crowd.people == self.people:
return True
else:
return False
def get_arrow_mask(self, img, color, thick_fun= ThicknessSigmoid(5)):
sum_of_xy = np.zeros(2)
sum_of_vector = np.zeros(2)
people = self.people
for pp in people:
sum_of_xy = sum_of_xy + pp.xy
sum_of_vector = sum_of_vector + pp.vector
start_center_xy = np.array(sum_of_xy / len(people), dtype=np.int)
res_vector = np.array(sum_of_vector / len(people), dtype=np.int)
print('res vec: ', res_vector)
# if dist(res_vector) <= 4:
# return None
# thickfun : 用人數去取得箭頭的粗細
thickness = thick_fun(len(people))
arrow = Arrow(start_center_xy, res_vector, color, thickness)
arrow_mask = arrow.get_mask(shape = img.shape)
return arrow_mask