-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_utils.py
76 lines (62 loc) · 1.99 KB
/
camera_utils.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
import collections
import datetime
output_string = []
last_characters = collections.deque()
now = 0
timestamp = 0
string_to_process = []
letter = 0
confs = 0
ACC = 30
def get_one_letter(confs, letters):
if confs:
max_value_per_confs = max(confs)
max_index = confs.index(max_value_per_confs)
letters = letters[max_index]
confs = confs[max_index]
return confs, letters
def get_time(letter):
global last_characters, timestamp
now = datetime.datetime.now()
timestamp = int(round(now.timestamp()))
last_characters.append([timestamp, letter])
# print(last_characters)
return last_characters
def create_dic(the_list):
dic = {x: the_list.count(x) for x in the_list}
return dic
def get_necessary_letter(the_dic):
max_key = max(the_dic, key=the_dic.get)
return max_key
def process_time():
global timestamp, last_characters, output_string
# print(last_characters)
# print(output_string)
if (timestamp - last_characters[0][0]) >= 3:
for i in range(len(last_characters)):
if last_characters[i][1] is not []:
string_to_process.append(last_characters[i][1])
last_characters.clear()
# print(string_to_process)
if string_to_process:
# print(last_characters)
dic = create_dic(string_to_process)
letter = get_necessary_letter(dic)
string_to_process.clear()
# print((dic[letter] * 100) / sum(dic.values()))
if (dic[letter] * 100) / sum(dic.values()) >= ACC:
# print(output_string)
if output_string:
if output_string[-1] != letter:
output_string.append(letter)
# print(output_string)
else:
output_string.append(letter)
# print(output_string)
def process(confs, letters):
global output_string
# print(confs, letters)
_, letters_ = get_one_letter(confs, letters)
# print(letters_)
get_time(letters_)
process_time()