-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_oop.py
59 lines (43 loc) · 1.97 KB
/
count_oop.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
class Count():
def __init__(self, ds_output, roi, names, count_out_classes, counted) -> None:
self.count_out_classes = count_out_classes
self.counted = counted
for detection in ds_output:
# Get variables
ds_cpoint = detection[0]
ds_id = detection[1]
ds_class = detection[2]
# To check if the ds_cpoint is into the roi
is_into_roi = (roi[0] < ds_cpoint[0] < roi[2]) and (
roi[1] < ds_cpoint[1] < roi[3])
# If is into the roi
if is_into_roi:
# fill the empty vector
if len(self.counted) == 0:
self.counted.append([ds_id, ds_class])
# get the classes detected
self.count_out_classes = dict.fromkeys(
[elem[1] for elem in self.counted], 0)
# count per class
for elem in self.counted:
self.count_out_classes[elem[1]] += 1
else:
# if the id is not in the list
if (ds_id not in [elem[0] for elem in self.counted]):
# count object
self.counted.append([ds_id, ds_class])
# get the classes detected
self.count_out_classes = dict.fromkeys(
[elem[1] for elem in self.counted], 0)
# count per class
for elem in self.counted:
self.count_out_classes[elem[1]] += 1
self.counter_text = [[key, names[key], self.count_out_classes[key]]
for key in self.count_out_classes.keys()]
def __str__(self) -> str:
output_text_counting = f"""
COUNTING:\n
Classes Detected: {self.count_out_classes}
Counter output: {self.counter_text}
"""
return output_text_counting