From 1ce993051edcbfd0156dc0be1c4fd67681f9d283 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 13 Sep 2020 08:23:41 -0500 Subject: [PATCH] add support for polygon masks --- config/config.example.yml | 7 ++++--- frigate/video.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index b317abe34..86c0b3e06 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -140,9 +140,10 @@ cameras: # fps: 5 ################ - ## Optional mask. Must be the same aspect ratio as your video feed. Value is either the - ## name of a file in the config directory or a base64 encoded bmp image prefixed with - ## 'base64,' eg. 'base64,asfasdfasdf....'. + ## Optional mask. Must be the same aspect ratio as your video feed. Value is any of the following: + ## - name of a file in the config directory + ## - base64 encoded image prefixed with 'base64,' eg. 'base64,asfasdfasdf....' + ## - polygon of x,y coordinates prefixed with 'poly,' eg. 'poly,0,900,1080,900,1080,1920,0,1920' ## ## The mask works by looking at the bottom center of the bounding box for the detected ## person in the image. If that pixel in the mask is a black pixel, it ignores it as a diff --git a/frigate/video.py b/frigate/video.py index f970086d3..df88b71f9 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -202,6 +202,12 @@ def track_camera(name, config, frame_queue, frame_shape, detection_queue, detect img = base64.b64decode(config['mask'][7:]) npimg = np.fromstring(img, dtype=np.uint8) mask = cv2.imdecode(npimg, cv2.IMREAD_GRAYSCALE) + elif config['mask'].startswith('poly,'): + points = config['mask'].split(',')[1:] + contour = np.array([[int(points[i]), int(points[i+1])] for i in range(0, len(points), 2)]) + mask = np.zeros((frame_shape[0], frame_shape[1]), np.uint8) + mask[:] = 255 + cv2.fillPoly(mask, pts=[contour], color=(0)) else: mask = cv2.imread("/config/{}".format(config['mask']), cv2.IMREAD_GRAYSCALE) else: