Skip to content

Instantly share code, notes, and snippets.

@boverby
Created November 7, 2020 16:44
Show Gist options
  • Save boverby/d172b9d6ce0e1b872d03083614711db7 to your computer and use it in GitHub Desktop.
Save boverby/d172b9d6ce0e1b872d03083614711db7 to your computer and use it in GitHub Desktop.
script to create mask file from scratch based on camera mask in frigate config file
#!/usr/bin/perl
use strict;
use warnings;
# see: https://github.com/blakeblackshear/frigate
# "snapshotMask.pl" - 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
# needed imagemagick/stable, libyaml-libyaml-perl/stable and libimage-magick-perl/stable for debian
use YAML::XS 'LoadFile';
#-------- modify to suit your environment ----[start]----------------------------------------------
my $CFGDIR="/opt/frigate/config";
my $CFGFILE="$CFGDIR/config.yml";
#-------- modify to suit your environment ----[end]------------------------------------------------
my %yaml = %{ LoadFile( $CFGFILE ) };
my @cameras = keys %{ $yaml{'cameras'} };
for my $c ( @cameras ){
my $mask = $yaml{'cameras'}{$c}{'mask'};
$mask =~ s/poly,// ;
#print "$c uses $mask\n";
my $cmd = qq[/usr/bin/convert -size 1920x1080 xc:black -fill white -stroke white -draw "polyline $mask" ${CFGDIR}/${c}mask.gif ];
`$cmd`;
$cmd = qq[/usr/bin/convert -size 1920x1080 xc:black -fill white -stroke white -draw "polyline $mask" ${CFGDIR}/${c}mask.bmp ];
`$cmd`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment