In this
I. Capturing an image using Raspberry Pi Camera V2.1
II. Record a video using a Raspberry Pi Camera
Things you need:
- A Raspberry Pi
- Raspberry Pi Camera V2.1 ( which I am using in this project)
We will see step by step procedure to install the Raspberry Pi camera module.
- Open the Raspberry Pi Camera V2.1 from the static bag (Gray transparent bag) carefully. Make sure you have discharged yourself from touching an earthed object. Connect the camera module to the socket given next to the HDMI – silver connectors that face the HDMI ( as shown in the image).
An important note: Connect the camera module into the Raspberry Pi and then plug into the power socket ( boot up) or else your camera might get damaged.
How to set up a Raspberry Pi? – Click Here
2. After booting up your Pi, from the command prompt run,
sudo apt-get upgrade
sudo apt-get update
sudo raspi-config
When you run the command for the configuration, click the 5th option called “Interface Options” to set up the camera module.
3. Click the “Pi camera” option to enable the Camera module in your Raspberry Pi. Click “Yes” and Reboot your Raspberry Pi.
Now your Raspberry Pi Camera is enabled in your Raspberry Pi! Now we will learn how to take a still using the camera.
I. Capturing an image using Raspberry Pi Camera V2.1
You can control the camera using a command-line tools or even a python library python-picamera.
The command for capturing still photographs: Raspistill
When you need to flip the image, run the following command.
Useful command line tools for setting an image:
- –
vf — Vertical flip - -hf — horizontal flip
- -w — set image width <size>
- -h — set image height <size>
- -p — preview window settings < ‘x,y,w,h’>
- -co — set image contrast <0 to 100>
- -sh — set image sharpness <0 to 100>
- -q — set jpeg quality <0 to 100>
Time Lapse video
A Time lapse video is a collection of hundreds and thousands of images of the same view over a period of time. You can set up the camera at one particular spot and capture images at a specific frequency with a single line of code. You can combine the images and make a video in
raspistill -t 10000 -t1 2000 -o image %04d.jpg
- -t 10000 — a period of 10 seconds
- -t1 2000 — takes a picture every 2 seconds
- image%04d — saves the file with a sequence number of the image
II. Record a video using a Raspberry Pi Camera
Raspivid is a tool to record a video using the Raspberry Pi Camera.
raspivid -o video.h264 -t 25000 -timed 3000, 6000
- -o video.h264 — saves the video in h264 format
- -t 25000 — records 25 seconds of video
- -timed 3000, 6000 — the alternate record of 3 seconds and pause for 6 seconds
Useful command line tools for recording a video
- -w — set image width <size> width can be between 64 and 1920 px
- -h — set image height <size> height can be between 64 and 1080 px
- -b — set bit rate
- -fps — specify the frames per second
To play the video, navigate to the location of the video file in the terminal using cd, then type the foll0wing command,
omxplayer video1.h264
Example Video Sample of Big Buck Bunny on Pi:
Enter this command in the terminal to view the video sample already available on the Pi.
omxplayer /opt/vc/src/hello_pi/hello_video/test.h264