Monday 18 November 2013

Capture images on webcam

I own a raspberry pi and have been thinking about getting the camera module, but still I haven't. One of the things I like to do is time lapse.
You can also do this with your web cam on your computer.

First check if your web cam is detected
$ ls -l /dev/video*
crw-rw----+ 1 root video 81, 0 nov 16 17:08 /dev/video0
Then install following programs
sudo apt-get install fswebcam
sudo apt-get install mencoder
Create your time lapse folder and use editor to create your tilme lapse file, the script.
mkdir timelapse
vim runtimelapse
Paste in the following:
#!/bin/bash
# Timelapse controller for USB webcam
frames=1440 # The numer of images to be taken
pause=10 # Dealy in seconds between images
DIR=~/timelapse
x=1
while [ $x -le $frames ]; do
filename=$(date -u +"%Y%m%d_%H%M-%S").jpg
fswebcam -d /dev/video0 -r 640x480 $DIR/$filename
x=$(( $x + 1 ))
sleep $pause;
done;
To make the script executable, use:
chmod 755 runtimelapse
Then run it using:
./runtimelapse
Now you have some number of images, time to create video
cd timelapse
ls *.jpg > list.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=640:480 -o timelapse.avi -mf type=jpeg:fps=24 mf://@list.txt
And now you have time lapse video.

Instructions on making timelapse using raspberry pi