Compare commits

..

9 Commits

Author SHA1 Message Date
Blake Blackshear
1771b9f286 update sample config 2020-10-17 07:37:52 -05:00
Blake Blackshear
56a9a46625 move the timestamp to bottom 2020-10-16 19:23:08 -05:00
Blake Blackshear
5174fc539f tweak size 2020-10-16 18:31:15 -05:00
Blake Blackshear
95cb97cf42 use the actual original shape 2020-10-16 17:59:17 -05:00
Blake Blackshear
53adfe0b09 scale font of timestamp dynamically 2020-10-16 17:50:40 -05:00
Blake Blackshear
8d4e155ece add ability to draw bounding boxes/timestamps on snapshots 2020-10-16 16:11:08 -05:00
Blake Blackshear
6069709035 handle empty best frames 2020-10-13 20:57:57 -05:00
Blake Blackshear
c9d7fbbd12 fix detector cleanup 2020-10-13 08:01:06 -05:00
Blake Blackshear
0b51f58de0 reduce zone filter bouncing 2020-10-13 07:50:14 -05:00
3 changed files with 32 additions and 9 deletions

View File

@@ -215,6 +215,7 @@ cameras:
snapshots:
show_timestamp: True
draw_zones: False
draw_bounding_boxes: True
################
# Camera level object config. If defined, this is used instead of the global config.

View File

@@ -164,7 +164,8 @@ def main():
for name, config in CONFIG['cameras'].items():
config['snapshots'] = {
'show_timestamp': config.get('snapshots', {}).get('show_timestamp', True),
'draw_zones': config.get('snapshots', {}).get('draw_zones', False)
'draw_zones': config.get('snapshots', {}).get('draw_zones', False),
'draw_bounding_boxes': config.get('snapshots', {}).get('draw_bounding_boxes', True)
}
config['zones'] = config.get('zones', {})
@@ -312,7 +313,7 @@ def main():
shm.close()
shm.unlink()
for detector in detectors:
for detector in detectors.values():
detector.stop()
for shm in camera_shms:
shm.close()
@@ -388,9 +389,11 @@ def main():
def best(camera_name, label):
if camera_name in CONFIG['cameras']:
best_object = object_processor.get_best(camera_name, label)
best_frame = best_object.get('frame', np.zeros((720,1280,3), np.uint8))
best_frame = cv2.cvtColor(best_frame, cv2.COLOR_YUV2BGR_I420)
best_frame = best_object.get('frame')
if best_frame is None:
best_frame = np.zeros((720,1280,3), np.uint8)
else:
best_frame = cv2.cvtColor(best_frame, cv2.COLOR_YUV2BGR_I420)
crop = bool(request.args.get('crop', 0, type=int))
if crop:

View File

@@ -181,10 +181,12 @@ class CameraState():
# check each zone
for name, zone in self.config['zones'].items():
contour = zone['contour']
# check if the object is in the zone and not filtered
if (cv2.pointPolygonTest(contour, bottom_center, False) >= 0
and not zone_filtered(obj, zone.get('filters', {}))):
current_zones.append(name)
# check if the object is in the zone
if (cv2.pointPolygonTest(contour, bottom_center, False) >= 0):
# if the object passed the filters once, dont apply again
if name in obj.get('zones', []) or not zone_filtered(obj, zone.get('filters', {})):
current_zones.append(name)
obj['zones'] = current_zones
# maintain best objects
@@ -266,7 +268,14 @@ class TrackedObjectProcessor(threading.Thread):
def snapshot(camera, obj):
if not 'frame' in obj:
return
best_frame = cv2.cvtColor(obj['frame'], cv2.COLOR_YUV2BGR_I420)
if self.camera_config[camera]['snapshots']['draw_bounding_boxes']:
thickness = 2
color = COLOR_MAP[obj['label']]
box = obj['box']
draw_box_with_label(best_frame, box[0], box[1], box[2], box[3], obj['label'], f"{int(obj['score']*100)}% {int(obj['area'])}", thickness=thickness, color=color)
mqtt_config = self.camera_config[camera].get('mqtt', {'crop_to_region': False})
if mqtt_config.get('crop_to_region'):
region = obj['region']
@@ -275,6 +284,16 @@ class TrackedObjectProcessor(threading.Thread):
height = int(mqtt_config['snapshot_height'])
width = int(height*best_frame.shape[1]/best_frame.shape[0])
best_frame = cv2.resize(best_frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
if self.camera_config[camera]['snapshots']['show_timestamp']:
time_to_show = datetime.datetime.fromtimestamp(obj['frame_time']).strftime("%m/%d/%Y %H:%M:%S")
size = cv2.getTextSize(time_to_show, cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, thickness=2)
text_width = size[0][0]
text_height = size[0][1]
desired_size = max(200, 0.33*best_frame.shape[1])
font_scale = desired_size/text_width
cv2.putText(best_frame, time_to_show, (5, best_frame.shape[0]-7), cv2.FONT_HERSHEY_SIMPLEX, fontScale=font_scale, color=(255, 255, 255), thickness=2)
ret, jpg = cv2.imencode('.jpg', best_frame)
if ret:
jpg_bytes = jpg.tobytes()