Template: RPi Camera Raspicam Guide
Install Raspicam (Optional)
If you use the Bullseye image (the newest image), you need to install the Raspicam for using the legacy stack.
Open a terminal and run the following commands
sudo apt-get update cd sudo apt install cmake git clone https://github.com/raspberrypi/userland cd userland ./buildme cp build/bin/* ~/bin/ sudo reboot
Enable Camera
To use the Raspicam application, you need to enable the camera first.
Open the raspi-config tool from the terminal
sudo raspi-config
Select Interfacing Options then Camera and press Enter. Choose Yes then Ok. Go to Finish and you’ll be prompted to reboot.
Test camera
raspistill
raspistill is the command line tool for capturing still photographs with a Raspberry Pi camera module.
raspistill -o cam.jpg
raspivid
raspivid is the command line tool for capturing video with a Raspberry Pi camera module.
raspivid -o vid.h264
raspiyuv
raspiyuv has the same set of features as raspistill but instead of outputting standard image files such as .jpgs, it generates YUV420 or RGB888 image files from the output of the camera ISP.
In most cases using raspistill is the best option for standard image capture, but using YUV can be of benefit in certain circumstances. For example if you just need a uncompressed black and white image for computer vision applications, you can simply use the Y channel of a YUV capture.
raspiyuv -o cam.jpg
Command Line Options
Option | Option(abbreviate) | Description |
---|---|---|
--preview | -p | Preview window settings <'x,y,w,h'> |
--fullscreen | -f | Fullscreen preview mode |
--nopreview | -n | Do not display a preview window |
--opacity | -op | Set preview window opacity |
--sharpness | -sh | Set image sharpness (-100 - 100) |
--contrast | -co | Set image contrast (-100 - 100) |
--brightness | -br | Set image brightness (0 - 100) |
--saturation | -sa | Set image saturation (-100 - 100) |
--ISO | -ISO | Set capture ISO (100 - 800) |
--vstab | -vs | Turn on video stabilisation |
--ev | -ev | Set EV compensation (-10 - 10) |
--exposure | -ex | Set exposure mode
|
--flicker | -fli | Set flicker avoidance mode
|
--awb | -awb | Set Automatic White Balance (AWB) mode
|
--imxfx | -ifx | Set image effect
|
--colfx | -cfx | Set colour effect <U:V> |
--metering | -mm | Set metering mode
|
--rotation | -rot | Set image rotation (0 - 359) |
--hflip | -hf | Set horizontal flip |
--vflip | -vf | Set vertical flip |
-roi | Set sensor region of interest | |
--shutter | -ss | Set shutter speed/time |
--drc | -drc | Enable/disable dynamic range compression
|
--stats | -st | Use stills capture frame for image statistics |
--awbgains | -awbg | |
--analoggain | -ag | Set blue and green gain, takes effect if --awb off is set |
--digitalgain | -dg | |
--mode | -md | |
--camselect | -cs | |
--annotate | -a | Enable/set annotate flags or text |
--annotateex | -ae | Set extra annotation parameters |
--stereo | -3d | |
--decimate | -dec | |
--3dswap | -3dswap | |
--settings | -set |
- Parameter for --shutter option
Camera Version | Max (ms) |
---|---|
OV5647 | 6000000 (i.e. 6s) |
IMX219 | 10000000 (i.e. 10s) |
IMX477 | 200000000 (i.e. 200s) |
- Parameter for --mode, -md
- OV5647
Mode | Resolution | Aspect Ratio | Frame Rate | FoV |
---|---|---|---|---|
0 | Automatic selection | |||
1 | 1920 x 1080 | 16:9 | 1-30fps | Partial |
2 | 2592 x 1944 | 4:3 | 1-15fps | Full Frame |
3 | 2592 x 1944 | 4:3 | 0.1666 - 1fps | Full Frame |
4 | 1296 x 972 | 4:3 | 1 - 42fps | Full Frame |
5 | 1296 x 730 | 16:9 | 1- 49fps | Full Frame |
6 | 640 x 480 | 4:3 | 42.1 - 60fps | Full Frame |
7 | 640 x 480 | 4:3 | 60.1 - 90fps | Full Frame |
- IMX219
Mode | Resolution | Aspect Ratio | Frame Rate | FoV |
---|---|---|---|---|
0 | Automatic selection | |||
1 | 1920 x 1080 | 16:9 | 0.1-30fps | Partial |
2 | 3280 x 2464 | 4:3 | 0.1-15fps | Full Frame |
3 | 3280 x 2464 | 4:3 | 0.1 - 15fps | Full Frame |
4 | 1640 x 972 | 4:3 | 1 - 42fps | Full Frame |
5 | 1296 x 730 | 16:9 | 1- 49fps | Full Frame |
6 | 640 x 480 | 4:3 | 42.1 - 60fps | Full Frame |
7 | 640 x 480 | 4:3 | 60.1 - 90fps | Full Frame |
- HQ Camera
Mode | Resolution | Aspect Ratio | Frame Rate | FoV |
---|---|---|---|---|
0 | Automatic selection | |||
1 | 2028 x 1080 | 169:90 | 0.1-50fps | Partial |
2 | 2028 x 1080 | 4:3 | 0.1-50fps | Full Frame |
3 | 4056x3040 | 4:3 | 0.005 - 10fps | Full Frame |
4 | 1332x990 | 74:55 | 50.1-120 fps | Partial |
- Parameter for --annotate
- The parameters are represented by bit masks in the metadata, which can be directly represented by addition. For example, 12 can represent the display time (4) and the display date (8), which is represented by the addition of 4+8 =12.
Configurable options:
value | parameter description |
---|---|
-a 4 | time |
-a 8 | date |
-a 12 | Time and date, actually 4 + 8 |
-a 16 | Shutter setting |
-a 32 | CAF settings |
-a 64 | gain setting |
-a 128 | Lens settings |
-a 256 | animation settings |
-a 512 | number of frames |
-a 1024 | black background |
-a "ABC %Y-%m-%d %X" | display text |
-a 4 -a "ABC %Y-%m-%d %X" | Display time/date in custom format |
-a 8 -a "ABC %Y-%m-%d %X" | Display time/date in custom format |
--annotateex, -ae #Set additional annotation parameters
--stereo, -3d
Set the binocular mode.
- sbs - side by side mode
- tb: - Portrait mode
- off - turn off binocular mode (default)
--decimate, -dec
Halve the width and height of the binocular image
--setting, -set
Output current camera settings
Raspistill Command Line Options
Option | Option(abbreviate) | Description |
---|---|---|
--width --height --quality |
-w -h -q |
Set image width <size> Set image height <size> Set JPEG quality <0 to 100> |
--raw | -r | Add raw Bayer data to JPEG metadata |
--output | -o | Output filename <filename> |
--latest | -l | Link latest frame to filename <filename> |
--verbose | -v | Output verbose information during run |
--timeout | -t | Time before the camera takes picture and shuts down |
--timelapse | -tl | time-lapse mode |
--framestart | --fs | |
--datetime | -dt | |
--timestamp | -ts | |
--thumb | -th | Set thumbnail parameters (x:y:quality) |
--demo | -d | Run a demo mode <milliseconds> |
--encoding | -e | Encoding to use for output file |
--restart | -rs | |
--exif | -x | EXIF tag to apply to captures (format as 'key=value') |
--gpsdexif | -gps | |
--fullpreview | ||
full preview mode | ||
--keypress | -k | Keypress mode |
--signal | -s | Signal mode |
--burst | -bm |
Raspivid Command Line Options
Option | Option(abbreviate) | Description |
---|---|---|
--width | -w | Set image width <size> |
--height | -h | Set image height <size> |
--bitrate | -b | Set bitrate |
--output | -o | Output filename <filename> |
--listen | -l | |
--verbose | -v | Output verbose information during run |
--timeout | -t | Time before the camera takes picture and shuts down |
--demo | -d | Run a demo mode <milliseconds> |
--framerate | -fps | Specify the frames per second to record |
--penc | -e | Display preview image after encoding |
--intra | -g | Specify the intra refresh period (key frame rate/GoP) |
--qp | -qp | Set quantisation parameter |
--profile | -pf | Specify H264 profile to use for encoding
|
--level | -lev | |
--irefresh | -if | |
--inline | --ih | Insert PPS, SPS headers |
--spstimings | --stm | |
--timed | -td | Do timed switches between capture and pause |
--keypress | -k | Toggle between record and pause on Enter keypress |
--signal | -s | Toggle between record and pause according to SIGUSR1 |
--split | -sp | |
--circular | --c | |
--vectors | -x | |
--flush | -fl | |
--save-pts | -pts | |
--codec | --cd | |
--initial | -i | Define initial state on startup |
--segment | -sg | Segment the stream into multiple files |
--wrap | -wr | Set the maximum value for segment number |
--start | -sn | Set the initial segment number |
--raw | -r | |
--raw-format | -rf |
Raspiyuv Command Line Options
Many of the options for raspiyuv are the same as those for raspistill. This section shows the differences.
- Unsupported options
--exif, --encoding, --thumb, --raw, --quality
- Extra options
Option | Option(abbreviate) | Description |
---|---|---|
--rgb | -rgb | Save uncompressed data as RGB888 |
--luma | -y | |
--bgr | -bgr |
For more information about the Raspicam, please refer to the Official Guides