One of the interesting feature on Raspberry pi is the camera interface. But it dosen’t work out of box to view the camera feed. There are several ways to do it.
There are few ways to get image or video feed from Raspberry Pi camera. Let’s explore through the options available.
Before we begin, make sure the Pi Camera is connected as per below
Please refer to this page for more detailed instructions. (By Raspberry Pi Foundation)
Option 1 – Using raspistill or raspivid
Simply type following command to obtain an image
raspistill -o cam.jpg
This command obtains image at full device resolution.
Get list of extensions usable for raspistill here
As for to obtain video, key in command as below
raspivid -0 video.h264 -t 10000
It take video for 10seconds and stores at Home folder
Get list of extensions usable for raspivid here
Option 2 – Using PiCamera
PiCamera is included by default in Raspian
In any case, if require installation, just key in commands as below;
sudo apt-get update
sudo apt-get install python-picamera python3-picamera
To obtain an image, create a cam.py file and insert the codes below
from time import sleep
from picamera import PiCamera
camera = PiCamera()
camera.resolution = (1024, 768)
# Camera warm-up time
Save the file. Run using terminal with command below. (Assuming file at home directory)
A sample test.jpg image will be stored at home folder. For more information click here.
For video recording, create new python file with code below and run in. You will obtain a test.h264 video at home folder.
camera = picamera.PiCamera()
camera.resolution = (640, 480)
Above method applicable to get images or video from Raspberry Pi camera module. In the next post we will cover on how to stream this camera feed.