>>> DOWNLOAD SCRIPT <<<  

#!/bin/bash

# valore alto significa sensibilita' alta
LIMITE=22
# qualita' jpeg
JPEG_Q="60%"
# messaggio vocale di uscita prematura
MSG_USCITA="stop"
# messaggio vocale di allarme
MSG_ALLARME="allarrme"

# nome foto significativa precedente
fname_0=""
# nome foto appena scattata
fname_1=""

echo Partenza tra 30 secondi...
sleep 30

while truedo

    fname_1="webcam_$(date +%Y%m%d-%H%M%S).png"
    echo "foto $fname_1"
    fswebcam -q -r 640x480 ---no-banner --png $fname_1
    if -n "$fname_0" ]; then
        DIFFERENZA=$(compare -metric PSNR $fname_0 $fname_1 null: 2>&1 | cut -d "." -f 1)
        echo "    diff=$DIFFERENZA"
        if $LIMITE -gt $DIFFERENZA ]; then
            echo "    DIFFERENZA tra $fname_0 e $fname_1"
            #espeak -v it+f5 "$MSG_ALLARME" &
            convert -quality $JPEG_Q $fname_0 $fname_0.jpg
            rm $fname_0
            fname_0=$fname_1
        else
            rm $fname_1
            echo "    no diff"
        fi
    else
        fname_0=$fname_1
    fi
    if -f "stop" ]; then
        echo "uscita forzata"
        rm stop
        sleep 1;
        espeak "$MSG_USCITA"
        break
    fi

done

# converte l'ultima immagine
if -f "$fname_1" ]; then
    convert -quality $JPEG_Q $fname_1 $fname_1.jpg
    rm $fname_1
fi
if -f "$fname_0" ]; then
    convert -quality $JPEG_Q $fname_0 $fname_0.jpg
    rm $fname_0
fi