Skip to content

Commit

Permalink
allow mask to be base64 encoded into the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Aug 8, 2020
1 parent 1f03c8c commit e6c6338
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ cameras:
# width: 720

################
## Optional mask. Must be the same aspect ratio as your video feed.
## 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....'.
##
## 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
Expand Down
8 changes: 7 additions & 1 deletion frigate/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import copy
import itertools
import json
import base64
from collections import defaultdict
from frigate.util import draw_box_with_label, area, calculate_region, clipped, intersection_over_union, intersection, EventsPerSecond, listen, PlasmaManager
from frigate.objects import ObjectTracker
Expand Down Expand Up @@ -189,7 +190,12 @@ def track_camera(name, config, global_objects_config, frame_queue, frame_shape,

# load in the mask for object detection
if 'mask' in config:
mask = cv2.imread("/config/{}".format(config['mask']), cv2.IMREAD_GRAYSCALE)
if config['mask'].startswith('base64,'):
img = base64.b64decode(config['mask'][7:])
npimg = np.fromstring(img, dtype=np.uint8)
mask = cv2.imdecode(npimg, cv2.IMREAD_GRAYSCALE)
else:
mask = cv2.imread("/config/{}".format(config['mask']), cv2.IMREAD_GRAYSCALE)
else:
mask = None

Expand Down

0 comments on commit e6c6338

Please sign in to comment.