Escribi este script para tomar fotos en secuencia con el objeto de crear un video de camara lenta de unos nidos de termitas que infectan mi habitat (en realidad, creo que
nosotros estamos infectando el habitat de ellos!), el Script llama a su vez a otros scripts que efectuan tareas especificas (Borrar el numero secuencial anterior, encender el Flash controlado via el GPIO, apagarlo, anotar el
timestamp en la imagen, renombrar el archivo con un numero secuencial y subirlo al servidor de almacenamiento).
El script era llamado cada minuto via una tarea
cron y de esta forma obtenia las imagenes, luego ensamble el video, esta vez en mi fiel Windows laptop.
Te recomiendo que direcciones las imagenes hacia un
RAMDISK, para evitar que destruyas la SD de tu raspi en corto tiempo por la gran cantidad de operaciones de lectura/escritura/borrado de las imagenes.
Scrip principal
Code: Select all
#!/bin/sh
####################################
### STILL IMAGES FULL SCRIPT ###
### (c) Marco-Luis SALCEDO TOVAR ###
### http://www.meteoven.org ###
####################################
# Stores the actual system date to 'MyDate' variable
MyDate="`date +'%d%b%Y ; %T'`"
#
# http://stackoverflow.com/questions/8937663/shell-script-to-check-wether-a-server-is-reachable
# Test if the local server is up and leave record in logfile, otherwise exit the script.
ping -c1 -W1 10.168.0.115 || echo "Fail at: $MyDate" >> /home/pi/VideoCaptures/PingReport.txt
#
# Change to the working directory
echo "Changing to 'VideoCapures' folder ..."
cd /home/pi/VideoCaptures
#
# Erase the image left by the previous process.
/home/pi/VideoCaptures/Eraser.sh
#
# Turn ON the flash ...
sudo /home/pi/VideoCaptures/flash.sh -on
#
# Take a still photo
/home/pi/VideoCaptures/CameraTest.sh
#
# Turn OFF the flash
sudo /home/pi/VideoCaptures/flash.sh -off
#
# Clear the GPIO buffer
sudo /home/pi/VideoCaptures/flash.sh -clear
#
# Write the time stamp in the image
/home/pi/VideoCaptures/AnnotateTest.sh
#
# Rename the image in sequential number.
/home/pi/VideoCaptures/RenameSeq.sh
#
# Upload image to remote server ...
/home/pi/VideoCaptures/UploadPicture.sh
echo "All tasks done!"
exit 0
CameraTest.sh
Code: Select all
#!/bin/sh
###
### EXIF Data:
### http://www.raspberrypi.org/phpBB3/viewtopic.php?f=43&t=46053&p=412488
###
### http://www.raspberrypi-spy.co.uk/2013/05/taking-hi-res-photos-with-the-pi-camera-module/
### http://regex.info/exif.cgi
### http://exif-viewer.com/
###
cd /RAMDisk
Now=ImageFileName.jpg
echo "Taking photo still:$Now"
# raspistill -v -q 100 -x auto -mm average --rotation 180 --nopreview -o $filename
raspistill -v -n -x GPS.GPSLatitude=10/1,25/1,351/100 -x GPS.GPSLatitudeRef=N -x GPS.GPSLongitudeRef=W -x GPS.GPSLongitude=71/1,27/1,302/100 -q 100 --rotation 180 --nopreview -ev 5 -awb auto -ex auto -mm average -o $Now
echo "Done !"
exit 0
AnnotateTest.sh
Code: Select all
#!/bin/sh
# Temperature example taken from:
# http://www.raspberrypi.org/phpBB3/viewtopic.php?f=31&t=33851
#
# CPUTemp="`sudo /opt/vc/bin/vcgencmd measure_temp | tr -d "=temp'C"`"
CPUTemp="`sudo /opt/vc/bin/vcgencmd measure_temp | tr -d "=temp"`"
CPUTemp=" - SoC Temp: $CPUTemp - "
AmbientTemp="Ambient Temp: N/A"
cd /RAMDisk
OverlayText="`date +'%H:%M:%S - %d-%B-%Y'`"
### Add overlay:
echo "Adding overlay: $OverlayText"
### http://www.raspberrypi-spy.co.uk/2013/06/adding-a-watermark-or-logo-to-a-timelapse-video-using-avconv/
### http://raspi.tv/2014/overlaying-text-and-graphics-on-a-photo-and-tweeting-it-pt-5-twitter-app-series
### convert your_photo.jpg -pointsize 36 -fill white -annotate +40+728 'your overlay text' your_output_photo.jpg
#convert -pointsize 80 -fill yellow -draw 'text 40,40 "'" $OverlayText"' " ' /home/pi/VideoCaptures/Now.jpg /home/pi/VideoCaptures/Now.jpg
convert ImageFileName.jpg -pointsize 40 -fill blue -annotate +40+80 "$OverlayText$CPUTemp$AmbientTemp" ImageFileName.jpg
echo "Done !"
exit 0
Suerte!