Raspberry Pi Camera Setup for Time-Lapse: Difference between revisions
Jump to navigation
Jump to search
Line 102: | Line 102: | ||
# PiCam | # PiCam | ||
* * * * * /home/pi/Development/motion_webcam/takePictures.sh > /dev/null 2>&1 | * * * * * /home/pi/Development/motion_webcam/takePictures.sh > /dev/null 2>&1 | ||
=== Create a time-lapse movie === | |||
* Create a new script <tt>mergeAllPicturesInOneAnimatedGIF.sh</tt>: | |||
#!/bin/bash | |||
# | |||
# Script: mergeAllPicturesInOneAnimatedGIF.sh | |||
# Author: Heiko Kretschmer | |||
# Purpose: Merge all .jpg into one animated .gif | |||
# | |||
# History: | |||
# 2014-03-30, 09:52, h: Creation. Note. default ticks in -delay is n/100 of a second | |||
# | |||
# Globals | |||
# | |||
GFOLDERSOURCE="/var/www/webcam-archive" | |||
GSUFFIXSOURCE="jpg" | |||
GTIMESTAMP="`date +'%Y-%m-%d'`" | |||
GFILETARGET="/var/www/webcam-archive/${GTIMESTAMP}.gif" | |||
# (Un)Main | |||
# | |||
convert -limit area 0 -delay 25 -loop 1 "${GFOLDERSOURCE}/*.${GSUFFIXSOURCE}" "${GFILETARGET}" | |||
* Add a crontab entry: | |||
# PiCam - Merge Images to time-lapse-movie | |||
0 0 * * * /home/pi/Development/motion_webcam/mergeAllPicturesInOneAnimatedGIF.sh > /dev/null 2>&1 | |||
=== Check if it works === | === Check if it works === | ||
* The snapshot: http://192.168.42.112/webcam/lastsnap.jpg (change to your [[Pi]]'s IPA!) | * The last snapshot: http://192.168.42.112/webcam/lastsnap.jpg (change to your [[Pi]]'s IPA!) | ||
* The | * The snapshot archive: http://192.168.42.112/webcam-archive (change to your [[Pi]]'s IPA!) | ||
=== dscvsdcvds === | === dscvsdcvds === |
Revision as of 10:45, 30 March 2014
This article describes the setup of the Raspberry Pi Camera to create a time-lapse movie.
Setup
Get package list
apt-get update
Update all packages
apt-get upgrade
Enable the camera
raspi-config
Then answer the following stupid questions ("really enable?" and "reboot now?"), and you're done.
Configuration
Since using motion was some hazzle I decied to try a KISS-approach, using only the raspistill and convert[1] to implement.
Make the Pi take pictures
Make PiCam Device accessible
Since /usr/lib/cgi-bin/ is the default CGI-directory...
- make sure, everyone can access the camera device[2]:
chmod o+rwx /dev/vchiq
Setup script for taking a picture
- create this script named takePicture.sh:
#!/bin/bash # # Globals # GFOLDERTARGET="/var/www/webcam-archive" GFILELOCK="${GFOLDERTARGET}/takePicture.lck" GFILELOCKAGEMAX="60" GTIMESTAMP="`date +'%Y-%m-%d_%H-%M-%S'`" GFILETARGET="${GFOLDERTARGET}/${GTIMESTAMP}.jpg" GFILELASTSNAP="/var/www/webcam/lastsnap.jpg" # # # # Main # # Check locking if [ -f "${GFILELOCK}" ]; then LOCKFILEAGE="`stat --format=\"%Z\" \"${GFILELOCK}\"`" NOW="`date +'%s'`" AGE="`expr ${NOW} - ${LOCKFILEAGE}`" if [ "${AGE}" -gt "${GFILELOCKAGEMAX}" ]; then echo "Lockfile is ${AGE} seconds old, removing it." rm "${GFILELOCK}" else echo "Lockfile is ${AGE} seconds old, exiting." exit 1 fi fi # # # Lock echo $$ > "${GFILELOCK}" # # timeout should not be 0, since images will be to dark and are noisy # Since my cam is mounted wrong, I prefer to flip it :) (and flop it) raspistill --nopreview -w 1024 -h 768 -o - | convert - -flip -flop - > "${GFOLDERTARGET}/lastsnap.tmp" mv "${GFOLDERTARGET}/lastsnap.tmp" "${GFILETARGET}" cp "${GFILETARGET}" "${GFILELASTSNAP}" # # Unlock rm "${GFILELOCK}" # # Exit exit 0
- create a folder named webcam and webcam-archive:
cd /var/www mkdir webcam chown pi webcam- mkdir webcam-archive chown pi webcam-archive
Setup script for taking pictures
- create this script named takePictures.sh[3]:
#!/bin/bash # # Globals GSNAPSHOTSPERMINUTE=4 GSNAPSHOTINTERVAL="`expr 60 / 4`" # # Main #for i in {0.."${GSNAPSHOTSPERMINUTE}"..1} # fail #for i in {0..4..1} # works for ((i=1; i<=${GSNAPSHOTSPERMINUTE}; i++)) do TIMEBEFORESNAPSHOT="`date +'%s'`" echo "Taking snapshot at `date`" /home/pi/Development/motion_webcam/takePicture.sh TIMEAFTERSNAPSHOT="`date +'%s'`" DURATIONOFSNAPSHOT="`expr ${TIMEAFTERSNAPSHOT} - ${TIMEBEFORESNAPSHOT}`" if [ "${DURATIONOFSNAPSHOT}" -lt "${GSNAPSHOTINTERVAL}" ]; then DELAY="`expr ${GSNAPSHOTINTERVAL} - ${DURATIONOFSNAPSHOT}`" echo "Sleeping for ${DELAY} seconds." sleep ${DELAY} fi done
- Add this to pi's crontab:
# PiCam * * * * * /home/pi/Development/motion_webcam/takePictures.sh > /dev/null 2>&1
Create a time-lapse movie
- Create a new script mergeAllPicturesInOneAnimatedGIF.sh:
#!/bin/bash # # Script: mergeAllPicturesInOneAnimatedGIF.sh # Author: Heiko Kretschmer # Purpose: Merge all .jpg into one animated .gif # # History: # 2014-03-30, 09:52, h: Creation. Note. default ticks in -delay is n/100 of a second # # Globals # GFOLDERSOURCE="/var/www/webcam-archive" GSUFFIXSOURCE="jpg" GTIMESTAMP="`date +'%Y-%m-%d'`" GFILETARGET="/var/www/webcam-archive/${GTIMESTAMP}.gif" # (Un)Main # convert -limit area 0 -delay 25 -loop 1 "${GFOLDERSOURCE}/*.${GSUFFIXSOURCE}" "${GFILETARGET}"
- Add a crontab entry:
# PiCam - Merge Images to time-lapse-movie 0 0 * * * /home/pi/Development/motion_webcam/mergeAllPicturesInOneAnimatedGIF.sh > /dev/null 2>&1
Check if it works
- The last snapshot: http://192.168.42.112/webcam/lastsnap.jpg (change to your Pi's IPA!)
- The snapshot archive: http://192.168.42.112/webcam-archive (change to your Pi's IPA!)
dscvsdcvds
How do the scripts work?
- The takePictures.sh script will be fired every minute and will take, launching takePicture.sh a picture avery 15 seconds (4 per minute)
- tbd