Do you allow this site to use Cookies?

The Raspberry Pi Camera Module is a 5 mega pixel add-on board that can be used for taking photos and high definition 1080p video which attaches to the Raspberry Pi's Camera Serial Interface (CSI).

The Raspberry Pi Camera module is a small 5 mega pixel camera board of just 25mm by 20mm that connects to the Raspberry Pi's Camera Serial Interface (CSI) connector with a ribbon cable. It has a picture resolution of 2592 x 1944 pixels and can take HD video (1920 x 1080) at 30 frames per second as well as 1280 x 720 and 640 x 480. The board and cable are delicate and sensitive to static so ideally will need to be mounted in a housing of some description.

Controlling the Camera

Three utilities have been developed along side the camera which are used to take photo's and control the settings. These are Raspistill for taking still images, Raspivid for recording video and Raspiyuv for taking Raw still images.

Other than capturing stills and videos these utilities are used to show a live preview, change settings such as brightness, sharpness, contrast, colour saturation and exposure settings. There are also different modes like the ones available for a digital camera such as Auto exposure mode, long exposure, sport, snow, spotlight, night, anti shake and various white balance modes.

Though there is a night setting for low light scenes the camera has an Infra-red filter on the lens so lighting a low light scene with infra-red lights will not be very effective.

Activating the Camera in Raspbian

To use the camera you will need the latest version of the Raspbian operating system, available here. To use the camera you will need the latest version of the Raspbian operating system, available here. If Raspistill, Raspivid or Raspiyuv are not available on your copy of Raspbian, you can either download the latest Raspbian image and install it to a SD card or update an your existing version of Raspbian with the following commands in LXterminal which will activate the camera features and install the utilities:

sudo apt-get update

sudo apt-get upgrade

If you don't have the latest firmware then you will also want to run

sudo rpi-update

Once all the update are complete you will need to enable to camera with the command;

sudo raspi-config
Go to the camera option and select enable and finish.

 

raspi-config-camera

Raspistill

Raspbistil images can be saved in jpeg, bmp, gif and png. Jpeg give a small file size and is hardware accelerated so it's the best option for timelapse capture.

Jpg images uses adjustable compression so some detail of the image is lost. At 100% quality you will barely notice any loss but at 50% quality the image will be poor. BMP and PNG are lossless formats so the files will be bigger than jpg files but will have a better quality image. Gif is limited to 256 colours with a small file size.

To take a picture and save the image called mypicture.jpg in the current folder the command is:

raspistill -t 1000 -o mypicture.jpg

-t is the delay in milliseconds before the image is taken after you press Enter. 1000 = 1 second.

To take a sequence of pictures as a timelapse sequence the command is:

raspistill -t 900000 -tl 30000 -o mypicture%d.jpg

-t total time for sequence, 90000 = 15 min
-tl how often to take a picture. 30000 = 30 seconds
%d = picture number. output would be mypicture1.jpg mypicture2.jpg mypicture3.jpg

If the file name is omitted then the image will be sent to stdout so it can be used with other software.

RaspiYUV

Raspiyuv has the same features as Raspistill but it generates a raw image file. Raw images made from the data directly from the camera sensor that have not been processed, so contain more graphical information than a picture that has been converted to jpg, bmp or png. This is more useful if you want to use an image editor to make advanced changes to lighting, colour or use for special effects.

Raspivid

Raspivid records video in HD 1080p (1920 x 1080) in the H264 Mpeg4 format which is the same video format used on Blu-Ray discs. Options allow you to alter the image size, frames per second, bitrate and view a preview.
Reducing the bitrate creates a smaller file but lowers the quality of the video image.
Frames per second can range between 2fps and 30fps

example command to record video:
raspivid -t 5000 -o myvideo.h264

This records 5 seconds in HD at 30fps to the current folder

raspivid -t 5000 -fps 25 -o myvideo.h264

as above but at 25 frames per second

Time delay photography

Raspistill can be set to take a photo after a certain amount of time has passed with the -t option but as Raspbian is being used there are other options.
A Cron is a built in feature of Raspbian, and other Linux distributions, that allows commands to be run at a set time and date or interval. So if you want to set-up a time-lapse sequence that starts off at dawn while you stay in bed then set-up a cron job by using the command crontab -e

This brings up the users cron tab for editing. The format is
"minutes" "hours" "day of month" "month" "day of the week" "command"

crontab

For this example I want to setup an hour long time-lapse that takes a still image every 15 seconds and save the images in a folder called dawn in the home folder but not to start until 5am.
At the bottom of the crontab page enter the command
* 05 10 06 * * raspistill -t 3600000 -tl 15000 -o ~/dawn/mypicture\%d.jpg

Note: for each picture to have it's own number when using a Cron Job the %d entry needs to be preceeded by a \  otherwise all files will have the same name, resulting in 1 picture.

A * is used for unused crontab options. 05 is under Hours so will be activated at 05 o'clock on the 10th day of the 6th month. If only hours was set then the command would be run at 5am every day.

Save the Crontab file by pressing CTRL & O together then enter. To exit the crontab press CTRL & X.

Then position the Raspberry Pi camera to patiently wait until morning and that's it, off to bed. Next morning all your pictures will be ready for you.

Don't forget:

  • To clear your command in the crontab when you have finished it as it will be run again when the criteria next match.
  • The Raspberry Pi uses the internet to update the time so if your RPi is not online you will need to work out what time the RPi will be at when you want to start taking photos and use that time instead.

If you are not connecting a display to your RPi while it is taking time-lapse photos or using SSH you can put a second line in the Crontab to shutdown the RPi when it is done.

enter a new line

15 06 10 06 * * sudo shutdown -h now

As the time-lapse goes on for an hour this line shuts down the Raspberry Pi at 6:15am.



This is a video I created using this method

 

Python PiCamera Library

The Rapberry Pi camera module can also be controlled within a Python program using the picamera library which is available in Raspbian for python versions 2.7 and 3.2.

The library gives you full direct control over the PiCamera and it's features.

See the documentation at picamera.readthedocs.org

 

Examples of how the Raspberry Pi camera is being used

These cameras with the Raspberry Pi are being used in some interesting ways already.

Such as helping to stop animal poaching in Africa. Raspberry Pi's are being used for video surveillance and listening for gun shots.

www.zsl.org/conservation/news/cameras-to-catch-poachers,1089,NS.html

Astronomy projects showing some nice video of the Moon and Saturn

zeusbox.net/blog/2013/06/update-raspberrypi-camera-for-astrophotography/

Taking pictures high up in the atmosphere from a Raspberry Pi that was attached to a weather balloon and sent off to document it's journey.

www.daveakerman.com/?p=1154

 

 

Raspistill Commands

raspistill Camera App v1.3.8

Runs camera for specific time, and take JPG capture at end if requested

usage: raspistill [options]

Image parameter commands

-?, --help    : This help information
-w, --width    : Set image width
-h, --height    : Set image height
-q, --quality    : Set jpeg quality
-r, --raw    : Add raw bayer data to jpeg metadata
-o, --output    : Output filename (to write to stdout, use '-o -'). If not specified, no file is saved
-l, --latest    : Link latest complete image to filename
-v, --verbose    : Output verbose information during run
-t, --timeout    : Time (in ms) before takes picture and shuts down (if not specified, set to 5s)
-th, --thumb    : Set thumbnail parameters (x:y:quality) or none
-d, --demo    : Run a demo mode (cycle through range of camera options, no capture)
-e, --encoding    : Encoding to use for output file (jpg, bmp, gif, png)
-x, --exif    : EXIF tag to apply to captures (format as 'key=value') or none
-tl, --timelapse    : Timelapse mode. Takes a picture every ms
-fp, --fullpreview    : Run the preview using the still capture resolution (may reduce preview fps)
-k, --keypress    : Wait between captures for a ENTER, X then ENTER to exit
-s, --signal    : Wait between captures for a SIGUSR1 from another process
-g, --gl    : Draw preview to texture instead of using video render component
-gc, --glcapture    : Capture the GL frame-buffer instead of the camera image
-set, --settings    : Retrieve camera settings and write to stdout
-cs, --camselect    : Select camera . Default 0
-bm, --burst    : Enable 'burst capture mode'
-md, --mode    : Force sensor mode. 0=auto. See docs for other modes available

Preview parameter commands

-p, --preview    : Preview window settings
-f, --fullscreen    : Fullscreen preview mode
-op, --opacity    : Preview window opacity (0-255)
-n, --nopreview    : Do not display a preview window

Image parameter commands

-sh, --sharpness    : Set image sharpness (-100 to 100)
-co, --contrast    : Set image contrast (-100 to 100)
-br, --brightness    : Set image brightness (0 to 100)
-sa, --saturation    : Set image saturation (-100 to 100)
-ISO, --ISO    : Set capture ISO
-vs, --vstab    : Turn on video stabilisation
-ev, --ev    : Set EV compensation
-ex, --exposure    : Set exposure mode (see Notes)
-awb, --awb    : Set AWB mode (see Notes)
-ifx, --imxfx    : Set image effect (see Notes)
-cfx, --colfx    : Set colour effect (U:V)
-mm, --metering    : Set metering mode (see Notes)
-rot, --rotation    : Set image rotation (0-359)
-hf, --hflip    : Set horizontal flip
-vf, --vflip    : Set vertical flip
-roi, --roi    : Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])
-ss, --shutter    : Set shutter speed in microseconds
-awbg, --awbgains    : Set AWB gains - AWB mode must be off
-drc, --drc    : Set DRC Level
-st, --stats    : Force recomputation of statistics on stills capture pass


Notes

Exposure mode options :
auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks

AWB mode options :
off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon

Image Effect mode options :
none, negative, solarise, sketch, denoise, emboss, oilpaint, hatch, gpen, pastel, watercolour, film, blur, saturation, colourswap, washedout, posterise, colourpoint, colourbalance, cartoon

Metering Mode options :
average,spot,backlit,matrix

Dynamic Range Compression (DRC) options :
off,low,med,high

Preview parameter commands

-gs, --glscene    : GL scene square,teapot,mirror,yuv,sobel
-gw, --glwin    : GL window settings

 

Raspivid Commands

raspivid Camera App v1.3.12

Display camera output to display, and optionally saves an H264 capture at requested bitrate


usage: raspivid [options]

Image parameter commands

-?, --help    : This help information
-w, --width    : Set image width . Default 1920
-h, --height    : Set image height . Default 1080
-b, --bitrate    : Set bitrate. Use bits per second (e.g. 10MBits/s would be -b 10000000)
-o, --output    : Output filename (to write to stdout, use '-o -')
-v, --verbose    : Output verbose information during run
-t, --timeout    : Time (in ms) to capture for. If not specified, set to 5s. Zero to disable
-d, --demo    : Run a demo mode (cycle through range of camera options, no capture)
-fps, --framerate    : Specify the frames per second to record
-e, --penc    : Display preview image *after* encoding (shows compression artifacts)
-g, --intra    : Specify the intra refresh period (key frame rate/GoP size). Zero to produce an initial I-frame and then just P-frames.
-pf, --profile    : Specify H264 profile to use for encoding
-td, --timed    : Cycle between capture and pause. -cycle on,off where on is record time and off is pause time in ms
-s, --signal    : Cycle between capture and pause on Signal
-k, --keypress    : Cycle between capture and pause on ENTER
-i, --initial    : Initial state. Use 'record' or 'pause'. Default 'record'
-qp, --qp    : Quantisation parameter. Use approximately 10-40. Default 0 (off)
-ih, --inline    : Insert inline headers (SPS, PPS) to stream
-sg, --segment    : Segment output file in to multiple files at specified interval
-wr, --wrap    : In segment mode, wrap any numbered filename back to 1 when reach number
-sn, --start    : In segment mode, start with specified segment number
-sp, --split    : In wait mode, create new output file for each start event
-c, --circular    : Run encoded data through circular buffer until triggered then save
-x, --vectors    : Output filename for inline motion vectors
-cs, --camselect    : Select camera . Default 0
-set, --settings    : Retrieve camera settings and write to stdout
-md, --mode    : Force sensor mode. 0=auto. See docs for other modes available


H264 Profile options :
baseline,main,high

Preview parameter commands

-p, --preview    : Preview window settings
-f, --fullscreen    : Fullscreen preview mode
-op, --opacity    : Preview window opacity (0-255)
-n, --nopreview    : Do not display a preview window

Image parameter commands

-sh, --sharpness    : Set image sharpness (-100 to 100)
-co, --contrast    : Set image contrast (-100 to 100)
-br, --brightness    : Set image brightness (0 to 100)
-sa, --saturation    : Set image saturation (-100 to 100)
-ISO, --ISO    : Set capture ISO
-vs, --vstab    : Turn on video stabilisation
-ev, --ev    : Set EV compensation
-ex, --exposure    : Set exposure mode (see Notes)
-awb, --awb    : Set AWB mode (see Notes)
-ifx, --imxfx    : Set image effect (see Notes)
-cfx, --colfx    : Set colour effect (U:V)
-mm, --metering    : Set metering mode (see Notes)
-rot, --rotation    : Set image rotation (0-359)
-hf, --hflip    : Set horizontal flip
-vf, --vflip    : Set vertical flip
-roi, --roi    : Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])
-ss, --shutter    : Set shutter speed in microseconds
-awbg, --awbgains    : Set AWB gains - AWB mode must be off
-drc, --drc    : Set DRC Level
-st, --stats    : Force recomputation of statistics on stills capture pass


Notes

Exposure mode options :
auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks

AWB mode options :
off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon

Image Effect mode options :
none, negative, solarise, sketch, denoise, emboss, oilpaint, hatch, gpen, pastel, watercolour, film, blur, saturation, colourswap, washedout, posterise, colourpoint, colourbalance, cartoon

Metering Mode options :
average,spot,backlit,matrix

Dynamic Range Compression (DRC) options :
off,low,med,high

 

RaspiYUV

raspiyuv Camera App v1.3.5

Runs camera for specific time, and take uncompressed YUV capture at end if requested

usage: raspiyuv [options]

Image parameter commands

-?, --help    : This help information
-w, --width    : Set image width
-h, --height    : Set image height
-o, --output    : Output filename . If not specifed, no image is saved
-v, --verbose    : Output verbose information during run
-t, --timeout    : Time (in ms) before takes picture and shuts down. If not specified set to 5s
-tl, --timelapse    : Timelapse mode. Takes a picture every ms
-rgb, --rgb    : Save as RGB data rather than YUV
-cs, --camselect    : Select camera . Default 0
-fp, --fullpreview    : Run the preview using the still capture resolution (may reduce preview fps)
-l, --latest    : Link latest complete image to filename
-k, --keypress    : Wait between captures for a ENTER, X then ENTER to exit
-s, --signal    : Wait between captures for a SIGUSR1 from another process
-set, --settings    : Retrieve camera settings and write to stdout
-bm, --burst    : Enable 'burst capture mode'

Preview parameter commands

-p, --preview    : Preview window settings
-f, --fullscreen    : Fullscreen preview mode
-op, --opacity    : Preview window opacity (0-255)
-n, --nopreview    : Do not display a preview window

Image parameter commands

-sh, --sharpness    : Set image sharpness (-100 to 100)
-co, --contrast    : Set image contrast (-100 to 100)
-br, --brightness    : Set image brightness (0 to 100)
-sa, --saturation    : Set image saturation (-100 to 100)
-ISO, --ISO    : Set capture ISO
-vs, --vstab    : Turn on video stabilisation
-ev, --ev    : Set EV compensation
-ex, --exposure    : Set exposure mode (see Notes)
-awb, --awb    : Set AWB mode (see Notes)
-ifx, --imxfx    : Set image effect (see Notes)
-cfx, --colfx    : Set colour effect (U:V)
-mm, --metering    : Set metering mode (see Notes)
-rot, --rotation    : Set image rotation (0-359)
-hf, --hflip    : Set horizontal flip
-vf, --vflip    : Set vertical flip
-roi, --roi    : Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])
-ss, --shutter    : Set shutter speed in microseconds
-awbg, --awbgains    : Set AWB gains - AWB mode must be off
-drc, --drc    : Set DRC Level
-st, --stats    : Force recomputation of statistics on stills capture pass


Notes

Exposure mode options :
auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks

AWB mode options :
off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon

Image Effect mode options :
none, negative, solarise, sketch, denoise, emboss, oilpaint, hatch, gpen, pastel, watercolour, film, blur, saturation, colourswap, washedout, posterise, colourpoint, colourbalance, cartoon

Metering Mode options :
average,spot,backlit,matrix

Dynamic Range Compression (DRC) options :
off,low,med,high

 

More Information

The Raspberry Pi Camera Module documentation is available here

More information about the Raspistill  image effects option -ifx here

More information about Raspistill image formats here


Add comment