Getting Image and Video from Raspberry Pi Camera

Getting Image and Video from Raspberry Pi Camera

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.

Requried items:
1. Raspberry Pi
2. Pi Camera ( Camera Module V2 or Pi NOIR Camera V2)
* Older versions are usable as well

Check out following articles to get started before proceesing to next section
Getting Started with Raspberry Pi
How to Flash Rapian into SD Card

Before we begin, make sure the Pi Camera is connected as per below

Getting Image and Video from Raspberry Pi Camera

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.start_preview()
# Camera warm-up time
sleep(2)
camera.capture('test.jpg')

Save the file. Run using terminal with command below. (Assuming file at home directory)

python cam.py

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.

import picamera 
camera = picamera.PiCamera()
camera.resolution = (640, 480)
camera.start_recording('my_video.h264')
camera.wait_recording(60)
camera.stop_recording()

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.

Share this:

Leave a Reply

You have to agree to the comment policy.