-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecurity.py
83 lines (66 loc) · 2.6 KB
/
security.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
class Frame:
# Update this class for every components used in the calculation
__slots__ = ('act_labs', 'act_confs', 'dobj', 'face_names', 'level')
# Recognized gestures counted as negative
NEGLABS = { "barang2_DR", "barang2_UR", "barang2_DL", "barang2_UL",
"barang1l_DR", "barang1l_UR", "barang1l_DL", "barang1l_UL",
"barang1r_DR", "barang1r_UR", "barang1r_DL", "barang1r_UL"}
# NEGLABS = { "barang_NE", "barang_NW", "barang_SE", "barang_SW"}
NEGOBJ = {"something"}
def __init__(self, act_labs, act_confs, dobj, face_names):
self.act_labs = act_labs
self.act_confs = act_confs
self.dobj = dobj
self.face_names = face_names
self.level = -1 # Uncalculated value
def calc(self):
# The calculation depth is basically endless.
# Some ideas to consider:
# - Pairing obj location with person/pose
# - Check face detection with detected person/pose
# - Positive behaviors
all = 0 # Count of total componenets
neg = 0 # Count of negative componenets
for (lab, conf) in zip(self.act_labs, self.act_confs):
if lab in self.NEGLABS:
neg += 1
elif conf < 0.2:
neg += 1
all += 1
# Disable all+=1 if you don't want other
# positive recog to skew the gesture result
# for obj in self.dobj:
# # An array: obj = [label, confidence, bounds]
# if obj[0] in self.NEGOBJ:
# neg += 1
# all += 1
# Disable if unknown face is permitted
# for face in self.face_names:
# if face == "Unknown":
# neg += 1
# all += 1
if all == 0:
all = 1
if neg > all:
neg = all
# if all == 0:
# # Force 0.5
# all = 2
# neg = 1
# Get security conclusion of a single frame
self.level = (all-neg)/all
# Count face unknown percentage
# for face in self.face_names:
# if face == "Unknown":
# fneg += 1
# fall += 1
# if fall == 0:
# fall = 1
# self.flevel = (fall-fneg)/fall
# def __init__(self, pairs):
# self.pairs = []
# self.uidx_list = set()
# self.body_parts = {}
# for pair in pairs:
# self.add_pair(pair)
# self.score = 0.0