Created
November 7, 2020 18:29
-
-
Save boverby/0b501e555779d19451178f6fa325e2c7 to your computer and use it in GitHub Desktop.
python version of mask maker for frigate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# snapshotMask.py file | |
# see: https://github.com/blakeblackshear/frigate | |
# "snapshotMask.py" - simple script to allow creation of mask images for frigate | |
# files dropped in config directory | |
# makes a graphic mask you can use later for transform like : | |
# ${SRCDIRECTORY}/${event}.jpg is a full size frame from mp4 file at frame_time | |
# composite -dissolve 70 -gravity center ${SRCDIRECTORY}/${event}.jpg /opt/frigate/config/hik193mask.bmp -alpha Set ${SRCDIRECTORY}/${event}.jpg | |
import yaml | |
import os | |
#-------- modify to suit your environment ----[start]---------------------------------------------- | |
CFGDIR="/opt/frigate/config" | |
CFGFILE=CFGDIR + "/config.yml" | |
#-------- modify to suit your environment ----[end]------------------------------------------------ | |
with open(CFGFILE) as file: | |
cfg = yaml.load(file, Loader=yaml.FullLoader) | |
cameraslist = list( cfg.get('cameras').keys() ) | |
for cam in cameraslist: | |
camerasMask = cfg.get('cameras')[cam].get('mask') | |
if ( camerasMask == None ): | |
continue | |
camerasMask = camerasMask.replace('poly,','') | |
shellcmd = "/usr/bin/convert -size 1920x1080 xc:black -fill white -stroke white -draw \"polyline "+camerasMask+"\" "+CFGDIR+"/"+cam+"mask.gif" | |
print( shellcmd ) | |
os.system( shellcmd ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment