-
Notifications
You must be signed in to change notification settings - Fork 2
/
predict_person_congestion.py
45 lines (35 loc) · 1.18 KB
/
predict_person_congestion.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
import collections
# Connect firebase Realtime DB
import json
import firebase_admin
from firebase_admin import credentials, db
# Load the database URL from the config file
with open('serviceDatabaseUrl.json') as f:
config = json.load(f)
database_url = config['databaseURL']
cred = credentials.Certificate("./serviceAccountKey.json")
firebase_admin.initialize_app(cred, {'databaseURL': database_url})
def calculate_congestion(datas, frame, filming_location):
# 80 percent of summary_frame
criterion = int(0.8 * frame)
# Count id values
count_person = dict(collections.Counter(datas))
count_standing = 0
for i in count_person.values():
if i > criterion:
count_standing += 1
if count_standing < 14:
level = 'Spare'
elif count_standing < 17:
level = 'General'
elif count_standing < 22:
level = 'Caution'
else:
level = 'Congestion'
# Save predict result to firebase Realtime Database
data_path = 'dataList/Congestion/' + str(filming_location)
ref = db.reference(data_path)
ref.update({'level': level,
'person': count_standing,
})
return level, count_standing