1 of 30

Webcams and the Raspberry Pi

Camera Module

@ben_nuttall

2 of 30

USB Webcam

apt-get install fswebcam

3 of 30

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'.

4 of 30

fswebcam - Basic Usage

5 of 30

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'.

6 of 30

fswebcam - Specify resolution

7 of 30

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'.

8 of 30

fswebcam - Specify no banner

9 of 30

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 &

10 of 30

Bash Script

#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M")

fswebcam -r 1280x720 --no-banner /home/pi/webcam/$DATE.jpg

11 of 30

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'.

12 of 30

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

13 of 30

Watch

pi@raspberrypi ~ $ watch ls webcam

Every 2.0s: ls webcam

2013-06-07_2244.jpg

2013-06-07_2245.jpg

14 of 30

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

15 of 30

Camera Module

16 of 30

Camera Module

http://shop.pimoroni.com

17 of 30

raspi-config

pi@raspberrypi ~ $ sudo raspi-config

18 of 30

raspistill - Basic Usage

raspistill -o cam.jpg

19 of 30

20 of 30

raspistill - Vertical and Horizontal Flip

raspistill -vf -hf -o cam2.jpg

21 of 30

22 of 30

How many megapixels has yours got??

2592 x 1944 = 5,038,848 -> 5mpx

23 of 30

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

24 of 30

Bash Script

#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M")

raspistill -vf -hf -o /home/pi/camera/$DATE.jpg

25 of 30

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

26 of 30

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/

27 of 30

Time Lapse

28 of 30

raspivid - Basic Usage

raspivid -o vid.h264

29 of 30

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

30 of 30

Webcams and the Raspberry Pi

Camera Module

@ben_nuttall

Slides at bennuttall.com/talks