Raspberry Pi Security Camera
This project aims to look at the suitability of the Raspberry Pi for use as the basis of a home security video and stills camera. It follows on from our previous to look at the generic capabilites of the Raspberry Pi.
There are a number of options open to us with this project and this is what we are aiming for:
- We have assumed a Raspberry Pi every camera node but, it is possible to have multiple USB webcams on one Raspberry Pi.
- Whilst we are looking at cameras with good low light performance, we would also like to have support LEDs, which are turned enabled at dusk and disabled again at dawn. They are then switched on when the camera is recording.
- It would be good to power the device using POE.
- The camera could be configured to record time-lapse still images.
- When motion is detected the camera would record video (or a set amount of time). Motion detection could be via exteranl PIR sensor or a motion detection algorithm. We think the former would work more reliably.
- The camera will handle general requests fro streamed video or stills.
- The captured images and video will be FTP'd to a central server.
For this project we plan to run the Raspberry Pi as a 'headless server'. This means no display, keyboard or mouse connected.
It is advisable to change the root password using the
Arch Linux ARM Operating System
All of the previous forums and posts we had seen suggested that the Arch Linux operating system has the best support for cameras and video, so we have decided to use it for this project. Jermemy Blyth's blog on how to turn a Raspberry Pi into an IP netcam is also using the Arch Linux OS.
We have had more much more success with the latest Wheezy build though.
Like a few other people, we have been experiencing erratic keyboard behaviour when using the Arch Linux OS. This was not an issue when using the Debian build, along with the same PSU, Belkin 6-port USB hub but we were using a different keyboard. This manifests itself most often as a key press being repeated many times. Our testing showed that the keyboard worked reliably if it was plugged into a USB port on the Raspberry Pi.
We have also noticed that the keyboard key mapping is wrong.
We then updated and installed the packages using the following commands:
pacman -S mplayer
pacman -S ffmpeg
This is the config file we used:
ffserver -f /root/ffserver.conf & ffmpeg -v 2 -r 5 -s 640x480 -f video4linux2 -i /dev/video0 http://localhost:8090/webcam.ffm
We are trying a number of different webcams. Ideally we want to capture still images and video at around 720p (1280 × 720 pixels). The list of supported webcams can be found here.
Philips PCVC740K ToUcam Pro
We started this project with this old Philips ToUcam Pro II PCVC840K in mind. It's an old webcam but a very good one for which Windows 7 drivers are no longer available. This camera is popular for digital astronomy and long exposure imaging. By modern standards, its 640 × 480 pixel resolution is not brilliant but, it's fine for this application.
We had a few issues with this camera. Under Debian it is detected and works OK but, the image is corrupted. If you plug it straight into the Raspberry Pi USB port it draws too much current and in our case stopped the network interface from working. It has to be used with a USB hub. We couldn't get it working under ARch Linux either :-(
Logitech Quickcam for Notebooks
This webcam is another old one we had lying around. We couldn't even get the RPi to recognise it as a device. It's a shame as it is very compact and would fit in our dome housing easily.
Logitech Quickcam Zoom
We had a few problems with earlier versions of the operating system but this seems to be working well now. It is limited to 640 × 480 pixels.
Logitech Quickcam Pro 9000
This camera is listed as a supported device and seems to work best out of all the webcams we have tested. It can take nice high resolution still images. The only downside of it, is that it is too big to fit in our dome housing.
Logitech C525 HD
We have bought this Logitech C525 HD (720p) webcam as it fits nicely in our dome. We can even mount it both ways up, to save having to flip the image in software. It's very compact and has the lens in the center of the camera, which makes it much easier to mount in our dome. We have successfully captured still images at 640 × 480, 960 × 720, 1280 × 960, 1712 × 960, 1792 × 1008 and 1920 × 1080 pixels. Another thing that's quite handy is the fact that the LEDs don't come on when it is taking a picture.
This camera also seems to work pretty well in low light and has the ability to auotmatically set exposure levels. This might be an issue if an external security is going to be switched on to capture and image though.
We have bought a dummy dome camera to house our webcam. The great thing about this model is that it is used for real IP networked cameras. The dummy version just has the camera module replaced with a blank circuit board. We picked up three of these on eBay for about £5 each. Bargain!
Raspberry Pi Camera Module
On 18th May 2012, the Raspberry Pi team announced that they were looking to provide a camera module. It is aimed at robotics and home automation applications and the protoype is an 8Mpixel camera but, the launched version is likely to be lower resolution to keep the costs down. It will plug into the CSI pins exposed in the middle of the Raspberry Pi.
The Raspberry Pi camera module is capable of 1080p video recording at 30fps.
Some sample camera board video output was posted recently (3rd Dec 2012):
The camera module has the perfect hole spacing to mount in our dummy domes.
Once mounted inside, the cable has to feed through a slot in the base and in to the Raspberry Pi.
We have also used the camera module in our Raspberry Pi Dashcam project and this covers the camera module software in detail.
It is possible to get 3rd party ribbon cables for connecting the RPi camera modules. We have seen them as long as 100cm. This makes it easy to use in some applications. The one shown here is 50cm long and used in our smart front door project.
RPi Camera Module Tests
We have done a number of tests using the camera module to see how quick it is to capture images of different sizes and quality. The is done using the command:
time -p raspistill -n -o test.jpg -ex auto -awb off -mm average -q 75 -t 0
Note that the default image size is 2592 × 1944 pixels.
Some example results:
- 2592 × 1944 pixels, Q = 100, time = 1.03s, file = 2.4MB
- 1920 × 1080 pixels, Q = 100, time = 0.90s, file = 1.1MB
- 1280 × 720 pixels, Q = 100, time = 0.83s, file = 412KB
- 2592 × 1944 pixels, Q = 90, time = 0.95s, file = 2.2MB
- 1920 × 1080 pixels, Q = 90, time = 0.89s, file = 1.0MB
- 1280 × 720 pixels, Q = 90, time = 0.89s, file = 404KB
- 2592 × 1944 pixels, Q = 75, time = 0.96s, file = 2.4MB
- 1920 × 1080 pixels, Q = 75, time = 0.89s, file = 1.1MB
- 1280 × 720 pixels, Q = 75, time = 0.83s, file = 426KB
The above tests showed that there is not much speed improvement by capturing smaller images or lower quality ones. Our tests on different types of metering showed no significant variations.
The RPi camera module is very poor in low light conditions. Because it has such a tiny sensor and lens it really stuggles and this limits is uses for security cameras at night time.
Raspberry Pi NOirCamera Module
The new 'NOir' camera module with no infra-red cut-off filter. This is basically the normal camera module but with the infra-red cut-off filter removed to enable low-light and IR-illuminated image and video capture. The PCB is black to differentiate it from the normal camera module.
We have had a lot of success with fswebcam. This is installed with the
sudo apt-get install fswebcam command.
fswebcam -d /dev/video0 -r 640x480 test.jpeg captures a still image to file. We could go up to 1920 × 1080 pixels.
We installed this software with the command
sudo apt-get install uvcdynctrl.
Running the command
uvcdynctrl -f results in a list of supported frame formats and resolutions. We have now managed to capture images successfully at 1920 × 1080 pixels and 1280 × 720 pixels but still image capture is pretty slow. At the highest rsolution is can take nearly 6 seconds to capture a still image.
So far we have got a functioning IP netcam but the resolution is quite low and the frame rate is also slow. We have had a lot more success in capturing high quality still images using fswebcam and a Logitech C525 HD camera and this is our preferred route right now.