Webcams and the Raspberry Pi
Camera Module
@ben_nuttall
USB Webcam
apt-get install fswebcam
fswebcam - Basic Usage
fswebcam image.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
Corrupt JPEG data: 2 extraneous bytes before marker 0xd4
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'image.jpg'.
fswebcam - Basic Usage
fswebcam - Specify resolution
fswebcam -r 1280x720 image2.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
--- Capturing frame...
Corrupt JPEG data: 1 extraneous bytes before marker 0xd5
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'image2.jpg'.
fswebcam - Specify resolution
fswebcam - Specify no banner
fswebcam -r 1280x720 --no-banner image3.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
--- Capturing frame...
Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to 'image3.jpg'.
fswebcam - Specify no banner
SSH / SCP
ben@wheatley:~$ ssh pi@192.168.1.10
pi@raspberrypi ~ $ fswebcam -r 1280x720 --no-banner image4.jpg
pi@raspberrypi ~ $ ls
Desktop image2.jpg image3.jpg image4.jpg image.jpg python_games
pi@raspberrypi ~ $ exit
ben@wheatley:~$ scp pi@192.168.1.10:image4.jpg .
ben@wheatley:~$ ls
Desktop Documents Downloads image.jpg Music Pictures Videos
ben@wheatley:~$ scp pi@192.168.1.10:*.jpg .
ben@wheatley:~$ ls
Desktop Documents Downloads image2.jpg image3.jpg image4.jpg image.jpg
Music Pictures Videos
ben@wheatley:~$ eog image.jpg &
Bash Script
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
fswebcam -r 1280x720 --no-banner /home/pi/webcam/$DATE.jpg
Bash Script
pi@raspberrypi ~ $ ls
Desktop python_games webcam.sh
pi@raspberrypi ~ $ mkdir webcam
pi@raspberrypi ~ $ ls
Desktop python_games webcam webcam.sh
pi@raspberrypi ~ $ ./webcam.sh
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
--- Capturing frame...
Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to '/home/pi/webcam/2013-06-07_2338.jpg'.
Crontab
pi@raspberrypi ~ $ crontab -e
{Note this will open in your default editor, usually nano - mine is vim}
# m h dom mon dow command
* * * * * /home/pi/webcam.sh 2>&1
crontab: installing new crontab
Watch
pi@raspberrypi ~ $ watch ls webcam
Every 2.0s: ls webcam
2013-06-07_2244.jpg
2013-06-07_2245.jpg
Watch
pi@raspberrypi ~ $ watch ls webcam
Every 2.0s: ls webcam
2013-06-07_2244.jpg
2013-06-07_2245.jpg
2013-06-07_2246.jpg
Camera Module
Camera Module
raspi-config
pi@raspberrypi ~ $ sudo raspi-config
raspistill - Basic Usage
raspistill -o cam.jpg
raspistill - Vertical and Horizontal Flip
raspistill -vf -hf -o cam2.jpg
How many megapixels has yours got??
2592 x 1944 = 5,038,848 -> 5mpx
How many megabytes is it??
~ 2.4MB
~ 425 photos per GB
1 photo per minute -> 1GB ~ 7 hours
~ 144MB per hour / 3.3GB per day
Bash Script
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
raspistill -vf -hf -o /home/pi/camera/$DATE.jpg
Bash Script
pi@raspberrypi ~ $ ls
Desktop python_games camera.sh
pi@raspberrypi ~ $ mkdir camera
pi@raspberrypi ~ $ ls
Desktop python_games camera camera.sh
pi@raspberrypi ~ $ ./camera.sh
pi@raspberrypi ~ $ ls camera
2013-06-08_0017.jpg
pi@raspberrypi ~ $ crontab -e
# m h dom mon dow command
* * * * * /home/pi/camera.sh 2>&1
rsync
ben@wheatley:~$ mkdir camera
ben@wheatley:~$ ls
camera Desktop Documents Downloads Music Pictures Videos
ben@wheatley:~$ rsync -avz -e ssh pi@192.168.1.10:camera/ camera/
Time Lapse
raspivid - Basic Usage
raspivid -o vid.h264
Manchester Raspberry Jam
- First* Raspberry Jam in the world
- Best** Raspberry Jam in the world
- Monthly at Madlab
- Talks and demos, but mostly just hacking
- Family friendly
* truth
** may be opinion
Webcams and the Raspberry Pi
Camera Module
@ben_nuttall
Slides at bennuttall.com/talks