This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 170
/
settings.py
232 lines (202 loc) · 9.07 KB
/
settings.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
'''
App settings.
'''
import os
import ast
ENVS_READY = True
# Absolute/relative path to video file
# E.g ./data/videos/sample_traffic_scene.mp4
if os.getenv('VIDEO'):
VIDEO = os.getenv('VIDEO')
else:
print('Path to video file not set.')
ENVS_READY = False
# Wait for video file to be available instead of exiting immediately if it doesn't exist.
# This is useful for when Ivy is used to process a video stream that has not yet started.
try:
WAIT_FOR_CAPTURE = ast.literal_eval(os.getenv('WAIT_FOR_CAPTURE', 'False'))
except ValueError:
print('Invalid value for WAIT_FOR_CAPTURE. It should be either True or False.')
ENVS_READY = False
if WAIT_FOR_CAPTURE:
try:
WAIT_FOR_CAPTURE_TIMEOUT = int(os.getenv('WAIT_FOR_CAPTURE_TIMEOUT', '300')) # in seconds
except ValueError:
print('Invalid value for WAIT_FOR_CAPTURE_TIMEOUT. It should be a positive integer.')
ENVS_READY = False
else:
WAIT_FOR_CAPTURE_TIMEOUT = 0
# Specify a detection Region of Interest (ROI)
# i.e a set of vertices that represent the area (polygon) where you want detections to be made
# E.g [(750, 405), (1094, 398), (1569, 1028), (501, 1028)]
# Default: [(0, 0), (frame_width, 0), (frame_width, frame_height), (0, frame_height)] (i.e the whole video frame)
try:
USE_DROI = ast.literal_eval(os.getenv('USE_DROI', 'False'))
except ValueError:
print('Invalid value for USE_DROI. It should be either True or False.')
ENVS_READY = False
if USE_DROI:
try:
DROI = ast.literal_eval(os.getenv('DROI'))
except ValueError:
print('Invalid value for DROI. It should be a list of coordinates (2-tuples).')
ENVS_READY = False
# Display/overlay the detection ROI on the video
try:
SHOW_DROI = ast.literal_eval(os.getenv('SHOW_DROI', 'False'))
except ValueError:
print('Invalid value for SHOW_DROI. It should be either True or False.')
ENVS_READY = False
# Display cumulative counts on the video
try:
SHOW_COUNTS = ast.literal_eval(os.getenv('SHOW_COUNTS', 'True'))
except ValueError:
print('Invalid value for SHOW_COUNTS. It should be either True or False.')
ENVS_READY = False
# Maximum consecutive detection failures i.e number of detection failures
# before it's concluded that an object is no longer in the frame
try:
MCDF = int(os.getenv('MCDF', '2'))
except ValueError:
print('Invalid value for MCDF. It should be a positive integer.')
ENVS_READY = False
# Maximum consecutive tracking failures i.e number of tracking failures
# before the tracker concludes the tracked object has left the frame
try:
MCTF = int(os.getenv('MCTF', '3'))
except ValueError:
print('Invalid value for MCTF. It should be a positive integer.')
ENVS_READY = False
# Detection interval i.e number of frames before detection is carried out again
# (in order to find new objects and update the trackers of old ones)
try:
DI = int(os.getenv('DI', '10'))
except ValueError:
print('Invalid value for DI. It should be a positive integer.')
ENVS_READY = False
# Model/algorithm to use for object detection (options: yolo, tfoda, detectron2, haarcascade)
DETECTOR = os.getenv('DETECTOR', 'yolo')
# Algorithm to use for object tracking (options: kcf, csrt)
TRACKER = os.getenv('TRACKER', 'kcf')
# Record object counting as video
try:
RECORD = ast.literal_eval(os.getenv('RECORD', 'False'))
except ValueError:
print('Invalid value for RECORD. It should be either True or False.')
ENVS_READY = False
# Set path where recorded video will be stored
if RECORD:
if os.getenv('OUTPUT_VIDEO_PATH'):
OUTPUT_VIDEO_PATH = os.getenv('OUTPUT_VIDEO_PATH')
else:
print('Output video path not set.')
ENVS_READY = False
# Run VCS without UI display
try:
HEADLESS = ast.literal_eval(os.getenv('HEADLESS', 'False'))
except ValueError:
print('Invalid value for HEADLESS. It should be either True or False.')
ENVS_READY = False
# Specify one or more counting lines
# A counting line is represented by a label and line segment
# E.g {'label': 'A', 'line': [(667, 713), (888, 713)]}
if os.getenv('COUNTING_LINES'):
try:
COUNTING_LINES = ast.literal_eval(os.getenv('COUNTING_LINES'))
except ValueError:
print('Invalid value for COUNTING_LINES. It should be a list of lines.')
ENVS_READY = False
# Configs for Haar Cascade detector
if DETECTOR == 'haarcascade':
if os.getenv('HAAR_CASCADE_PATH'):
HAAR_CASCADE_PATH = os.getenv('HAAR_CASCADE_PATH')
else:
print('HAAR_CASCADE_PATH not set.')
ENVS_READY = False
# Configs for TFODA (Tensorflow Object Detection API) detector
if DETECTOR == 'tfoda' or DETECTOR == 'tfoda_new':
if os.getenv('TFODA_WEIGHTS_PATH') and \
os.getenv('TFODA_CONFIG_PATH') and \
os.getenv('TFODA_MODEL_DIR') and \
os.getenv('TFODA_CLASSES_PATH') and \
os.getenv('TFODA_CLASSES_OF_INTEREST_PATH') and \
os.getenv('TFODA_CONFIDENCE_THRESHOLD'):
TFODA_WEIGHTS_PATH = os.getenv('TFODA_WEIGHTS_PATH')
TFODA_CONFIG_PATH = os.getenv('TFODA_CONFIG_PATH')
TFODA_MODEL_DIR = os.getenv('TFODA_MODEL_DIR')
TFODA_CLASSES_PATH = os.getenv('TFODA_CLASSES_PATH')
TFODA_CLASSES_OF_INTEREST_PATH = os.getenv('TFODA_CLASSES_OF_INTEREST_PATH')
TFODA_CONFIDENCE_THRESHOLD = float(os.getenv('TFODA_CONFIDENCE_THRESHOLD'))
else:
print('TFODA_WEIGHTS_PATH, TFODA_CONFIG_PATH, TFODA_MODEL_DIR, TFODA_CLASSES_PATH, ' +
'TFODA_CLASSES_OF_INTEREST_PATH and/or TFODA_CONFIDENCE_THRESHOLD not set or invalid.')
ENVS_READY = False
# Configs for YOLO (You Only Look Once) detector
if DETECTOR == 'yolo':
if os.getenv('YOLO_WEIGHTS_PATH') and \
os.getenv('YOLO_CONFIG_PATH') and \
os.getenv('YOLO_CLASSES_PATH') and \
os.getenv('YOLO_CLASSES_OF_INTEREST_PATH') and \
os.getenv('YOLO_CONFIDENCE_THRESHOLD'):
YOLO_WEIGHTS_PATH = os.getenv('YOLO_WEIGHTS_PATH')
YOLO_CONFIG_PATH = os.getenv('YOLO_CONFIG_PATH')
YOLO_CLASSES_PATH = os.getenv('YOLO_CLASSES_PATH')
YOLO_CLASSES_OF_INTEREST_PATH = os.getenv('YOLO_CLASSES_OF_INTEREST_PATH')
YOLO_CONFIDENCE_THRESHOLD = float(os.getenv('YOLO_CONFIDENCE_THRESHOLD'))
else:
print('YOLO_WEIGHTS_PATH, YOLO_CONFIG_PATH, YOLO_CLASSES_PATH, YOLO_CLASSES_OF_INTEREST_PATH, ' +
'and/or YOLO_CONFIDENCE_THRESHOLD not set or invalid.')
ENVS_READY = False
# Configs for Detectron2 detector
if DETECTOR == 'detectron2':
if os.getenv('DETECTRON2_CONFIDENCE_THRESHOLD') and \
os.getenv('DETECTRON2_CONFIG_PATH') and \
os.getenv('DETECTRON2_WEIGHTS_PATH') and \
os.getenv('DETECTRON2_NUM_CLASSES') and \
os.getenv('DETECTRON2_CLASSES_PATH') and \
os.getenv('DETECTRON2_CLASSES_OF_INTEREST_PATH'):
DETECTRON2_CONFIDENCE_THRESHOLD = float(os.getenv('DETECTRON2_CONFIDENCE_THRESHOLD'))
DETECTRON2_CONFIG_PATH = os.getenv('DETECTRON2_CONFIG_PATH')
DETECTRON2_WEIGHTS_PATH = os.getenv('DETECTRON2_WEIGHTS_PATH')
DETECTRON2_NUM_CLASSES = int(os.getenv('DETECTRON2_NUM_CLASSES'))
DETECTRON2_CLASSES_PATH = os.getenv('DETECTRON2_CLASSES_PATH')
DETECTRON2_CLASSES_OF_INTEREST_PATH = os.getenv('DETECTRON2_CLASSES_OF_INTEREST_PATH')
else:
print('DETECTRON2_CONFIDENCE_THRESHOLD, DETECTRON2_CONFIG_PATH, DETECTRON2_WEIGHTS_PATH, DETECTRON2_NUM_CLASSES, ' +
'DETECTRON2_CLASSES_PATH and/or DETECTRON2_CLASSES_OF_INTEREST_PATH not set or invalid.')
ENVS_READY = False
# Log destinations
try:
ENABLE_CONSOLE_LOGGER = ast.literal_eval(os.getenv('ENABLE_CONSOLE_LOGGER', 'True'))
ENABLE_FILE_LOGGER = ast.literal_eval(os.getenv('ENABLE_FILE_LOGGER', 'True'))
except ValueError:
print('Invalid value for ENABLE_CONSOLE_LOGGER and/or ' +
'ENABLE_FILE_LOGGER. They should be either True or False.')
ENVS_READY = False
# Absolute/relative path to log files directory
if ENABLE_FILE_LOGGER:
LOG_FILES_DIRECTORY = os.getenv('LOG_FILES_DIRECTORY', './data/logs/')
# Log base 64 images
# Logging images will increase the size of your logs significantly
# However, if you intend to do some post-processing that involves images,
# you might want to have it on
try:
LOG_IMAGES = ast.literal_eval(os.getenv('LOG_IMAGES', 'False'))
except ValueError:
print('Invalid value for LOG_IMAGES. It should be either True or False.')
ENVS_READY = False
# Size of window used to view the object counting process
try:
DEBUG_WINDOW_SIZE = ast.literal_eval(os.getenv('DEBUG_WINDOW_SIZE', '(858, 480)'))
except ValueError:
print('Invalid value for DEBUG_WINDOW_SIZE. It should be a 2-tuple: (width, height).')
ENVS_READY = False
# Color of heads up display
try:
HUD_COLOR = ast.literal_eval(os.getenv('HUD_COLOR', '(255, 0, 0)'))
except ValueError:
print('Invalid value for HUD_COLOR. It should be a 3-tuple: (B, G, R).')
ENVS_READY = False
if not ENVS_READY:
raise Exception('One or more environment variables are either invalid or not set. ' +
'Please ensure all variables are properly set.')