Last active
January 2, 2021 11:24
-
-
Save BETLOG/cb83a4b400c2136b6de726291553167b to your computer and use it in GitHub Desktop.
generate-motionMaskPGMs.sh - for use with RPiWebCamInterface
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
#!/bin/bash | |
# betlog - 2021-01-02--21-07-42 | |
# | |
# USE: | |
# 1 - in the RPi_Cam_Web_Interface for your camera > camera settings > set image res to match video res > 'record image' > 'download videos and images' > download the image | |
# 2 - open the exported image in your eitor of choice > paint areas to be monitored for motion as white and everything else black > save the file (replace the original) | |
# 3a - if you have a service menu set up as per the gist: | |
# - right click the now black and white file > convert > 'RPiCamWebInterface - generate And Install motionMask' | |
# 3b - if you just want to execute from a terminal: | |
# - execute: "RPiCamWebInterface-generateAndInstall-motionMaskPGM.sh <filename created above>" | |
# 4 - wait a moment for the script to select the reachable nodes > select the target machine | |
# | |
# NOTE: right-click/service/context menu is the only check that input is an image | |
# NOTE: 2592x1944 - is normal/max cam image capture resolution...just BTW | |
# | |
if [[ ${#@} -gt 1 ]];then | |
kdialog --title "ERROR" --passivepopup "only ONE file can be used as a mask" 5 | |
exit | |
fi | |
targetHostList=" | |
pizerocam0 | |
pizerocam1 | |
pizerocam2 | |
pizerocam3 | |
" | |
# =============================================== | |
unset targetHostMenu | |
while IFS= read -r line; do | |
[[ -z $line ]] && continue | |
check=$(ping -qc 1 -W 1 ${line}) #silent | |
error=$? | |
[[ $error -eq 0 ]] && targetHostMenu+="TRUE $line " || targetHostMenu+="FALSE $line " | |
done<<<"$targetHostList" | |
while [[ -z $targetHostString ]]; do | |
targetHostString=$(zenity --title "SELECT HOST(S)" --text="${0##*/}" --list --checklist --column "create motionmap" --column "hostname" $targetHostMenu 2> /dev/null) | |
[[ $? -eq 1 ]] && exit | |
targetHostString=$(echo "$targetHostString"|sed 's/|/\n/') #to preserve the zenity cancel code | |
done | |
# echo "targetHostString: $targetHostString" | |
msg1="${0##*/}" | |
msg2="PROCESSING:\\n$targetHostString" | |
echo -ne "$msg1\\n$msg2\\n" | |
kdialog --title "$msg1" --passivepopup "$msg2" 5 | |
camImage="$1" | |
path=${1%/*} | |
# echo "camImage: $camImage" | |
# echo "path: $path" | |
camImageSize=$(identify -format '%wx%h' "$camImage") | |
# echo "camImageSize: $camImageSize" | |
case $camImageSize in | |
768x576) size=49x36;; | |
1296x972) size=82x61;; | |
1920x1080) size=121x68;; | |
*) | |
msg1="ERROR:" | |
msg2="not a valid image size (768x576, 1296x972 or 1920x1080 only)" | |
echo "$msg1 $msg2" | |
kdialog --title "$msg1" --passivepopup "$msg2" 5 | |
exit | |
;; | |
esac | |
while IFS= read -r targetHost;do | |
[[ -z $targetHost ]] && continue | |
echo "removing old masks from $targetHost" | |
ssh -q $targetHost "sudo rm /tmp/*.pgm 2> /dev/null; sudo rm /var/www/html/*.pgm 2> /dev/null" < /dev/null | |
# exportName="${path}/${targetHost}-motionMask${camImageSize}.pgm" | |
exportName="${path}/motionMask-${camImageSize}.pgm" | |
echo "generating: $exportName" | |
convert -resize $size! "$camImage" "$exportName" | |
echo "installing to: $targetHost" | |
scp -q ${exportName} $targetHost:/tmp | |
ssh -q $targetHost "sudo mv /tmp/*.pgm /var/www/html" < /dev/null # will be $exportName only | |
[[ $? -eq 0 ]] && result="FINISHED: $(ssh -q $targetHost "ls /var/www/html/*.pgm" < /dev/null)" || result="ERROR: $result" | |
echo "$result" | |
kdialog --title "${result%%: *}" --passivepopup "${result##*: }" 5 | |
done<<<"$targetHostString" | |
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
[Desktop Entry] | |
Type=Service | |
Icon=user-desktop | |
X-KDE-Priority=TopLevel | |
X-KDE-Submenu=Convert | |
X-KDE-ServiceTypes=KonqPopupMenu/Plugin | |
MimeType=image/* | |
Actions=RPiCamWebInterfacePGM | |
[Desktop Action RPiCamWebInterfacePGM] | |
Icon=view-process-all | |
Name=RPiCamWebInterface - generate And Install motionMask | |
Exec=/home/user/documents/scripts/raspberry/RPiCamWebInterface-generateAndInstall-motionMaskPGM.sh %U |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment