The RasPi has a cheap camera module you can just plug right into the board, and you can turn it into a surveillance camera really easily. In this article you will find out how to fit and set up your camera and adjust the basic settings to take stills or video.
Slice of Camera Pi
Fitting the camera module to the Pi is simplicity itself. The camera connector is right behind the ethernet port.
Just lift up the tab, gently insert the ribbon cable (silver side away from the ethernet port) and then gently push the tab down.
The hard part is done. Now we need to take pictures and videos.
Before you can use the camera you have to enable it. Type:
and select “Enable Camera” from the menu. Reboot and you’re done.
To take a still using the camera, just open up a terminal (or just boot your Pi and log in) and type the following:
-o flag means output, and “image.jpg” is the filename which can be anything you like. This goes for all the following code.
On your screen you will have a few seconds to frame up your shot as the live feed turns on for a few seconds, and the red running light on the front of the camera shows the camera is active. In a few seconds the display will vanish, meaning the frame has been taken and the frame saved to the disk.
and you will see a directory listing showing that the picture you took has been stored in the home directory.
Note: see the full RasPi documentation for full details about the kinds of picture you can grab.
For example, there is a timelapse mode, white balance settings, frames per second speeds up to 120fps and effects like posterise, solarise and film look.
For example, to grab a film-look frame, type:
The RasPi’s effects work by kicking off the effect in real time (much like the Quartz effects in QuickTime) and simply recording the screen. So the film noise is actually an animated noise overlay. For a solarised effect, type:
Or perhaps you would like to take a series of timelapse frames.
This means take a picture every 30 seconds for a total duration of 300 seconds or 5 minutes and save the images as “pic00001.jpg,” “pic00002.jpg,” etc.
This really is a full-featured little camera.
As well as being a still camera, the RasPi cam can also shoot 1080 HD video. To grab a segment of video, type:
This will grab a five-second chunk of video and encode it to the default 1920×1080 at 25 frames per second. (The camera tested was in the PAL region, so your mileage may vary.) The quality size and duration are set by default. To change the quality and duration you have to specify what you want.
For example, shooting a clip at 720p with a bitrate of 20Mb/s using a high quality H264 profile would be:
This will record a video of 25 seconds in length, specified by the
To turn the camera into an impromptu camcorder, you can set it so it will record and pause when you toggle the ENTER key using the
To stop recording and save, press “x,” then Enter.
To convert the h264 files to playable video, you need to use a file converter because the file is not usable on its own. We used FFMPEG on the Mac. Just drag the file onto the interface and convert it to something playable on your target machine.
Another problem is although the camera has a built-in anti-shake algorithm, there’s no substitute for the camera being still when shooting video. There are cases which feature a mount for the camera like this one, or you can mount them in a proper CCTV case like this, especially if you want to use it outside … but it’s just as easy to rig something up cheaply using mini tripods meant for smart phones and a little Blue Tack, like the following.
Almost all the features of the camera are programmable, meaning you can use it for fun and capturing events with stills or video … or with a little skill you can program it to take video only when it senses movement and save the files each time to a certain location tagged in the filenames or on the screen with the time and date.
If you add a power bank battery, a small screen and a script to boot the disk and run that last command with the ENTER toggle, you could even use the cam as an actual portable camcorder very easily. How very James Bond of you to make a video camera out of component parts!
There is a lot of fun to be had with the RasPi camera, and the limits are your ability to find the right commands to type in. In a future article, we will cover how to turn your RasPi into a network surveillance camera and view the output on your computer.
In the meantime, if you have any questions or tips about using the Raspberry Pi Camera Module for fun or work, please share them in the comments below.