From b2ff50ca2c40320a9f38e9e43bffbcb607d3950b Mon Sep 17 00:00:00 2001 From: MikEarpp <72660689+MikEarpp@users.noreply.github.com> Date: Mon, 12 Oct 2020 10:42:50 +0200 Subject: [PATCH] Update detect_objects.py --- detect_objects.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/detect_objects.py b/detect_objects.py index 294c76ca9..8b16cef55 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -441,7 +441,7 @@ def main(): def latest_mask(camera_name): if camera_name in CONFIG['cameras']: - if 'mask' in CONFIG['cameras'][camera_name] : + if 'mask' in CONFIG['cameras'][camera_name]: mask = CONFIG['cameras'][camera_name]['mask'] frame = latest_frame(camera_name, True) @@ -467,8 +467,17 @@ def main(): return "Inconsistent sizes, {}x{} and {}x{}.".format(frame.shape[0], frame.shape[1], the_mask.shape[0], the_mask.shape[1]), 404 else: + hardness = 0.5 + if 'mask_hardness' in CONFIG['cameras'][camera_name]: + try: + hn = float(CONFIG['cameras'][camera_name]['mask_hardness']) + if isinstance(hn, (int, float)) and not isinstance(hn, bool) and hn >= 0 and hn <= 1: + hardness = hn + except ValueError: + pass + # frame and mask fusion - ret, jpg = cv2.imencode('.jpg', cv2.addWeighted(frame, 0.5, the_mask, 0.5, 0)) + ret, jpg = cv2.imencode('.jpg', cv2.addWeighted(frame, 1-hardness, the_mask, hardness, 0)) response = make_response(jpg.tobytes()) response.headers['Content-Type'] = 'image/jpg' return response