-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the picamera wiki!
PiCamera Basic and Advanced Recipes adapted from "official" documentation for training purposes. The purpose of this document to record my experience in following the documentation prepared by Dave Jones.
- Capturing to a file
This example is a basic use of the capture
method in the PiCamera classs. The capture
method has the following parameters:
-
output: the value can a string (i.e. filename) or an object that has a
write
method; if this parameter is omitted then the image data is written to a buffer where overflow constraints are the responsibility of the client code. -
format: the value can a string or a MIME-type; if this parameter is omitted then the format is deduced from the filetype extension otherwise an exception,
PiCameraValueError
is raised. The supported formats are JPEG, PNG, GIF, BMP, YUV, RGB, RGBA, BGR, BGRA and RAW. -
use_video_port: the value is boolean and defaults to
False
whereby the higher quality image port is used. -
resize: a two element tuple specifying the width and height of the image if the default value None needs to be overriden
-
splitter_port: see PiCamera documentation if you really need to use this parameter
-
bayer: if the value is
True
then the Exif metadata receives the raw bayer data from the camera's sensor -
options: if the format is "jpeg" then the addtional parameters are:
-
quality: an integer from 1 to 100 representing the quality of the image; the default value is 85.
-
restart: the restart intervval for the encoder.
-
thumbnail: the size and quality of the thumbnail image as a tuple
(width, height, quality)
with the default being(64,48,35)
; if the value isNone
then no thumbnail is prepared.
- Capturing to a stream
The binary input/ouput method, BytesIO()
, instantiates a buffer memory to retain bytes without encoding, decoding or translation. This representation is useful for non-textual data. The optional parameter to the constructor method can be a buffer stream.
This method displays the preview overlay with a rendering instance based the parameter options. The complementary method, `stop_preview(), stops the rendering. This pair of methods can be used throughout the lifetime of the corresponding active PiCamera object. All camera properties are accessible during the preview mode of operation.
The capture format must be specified as a string for a MIME-type or one of the following standards:
- Capturing to a PIL Image
The seek
method has the following parameters:
- offset: given byte offset
- whence: int, optional, =0 for start (default), =1 for current, =2 for end
The Python Imaging Library (PIL) object has an open
method that processes the image header but operates on the image object using a lazy operation that requires an explicit setting of the seek
method.
- Capturing resized images
Many image processing applications may perform more efficiently at a resolution that is different than the camera setting. The resize parameter in the capture
method provides a simple way to accomplish this by leveraging the camera's hardware than the more compute intensive methods of the image processing libraries.
The resize data is passed as a tuple - (width, height). If resize is specified, or use_video_port is True, then Exif metadata cannot be included in JPEG output owing to a current firmware limitation.
- Capturing consistent images
There may occur a need to have some consistency for all images across a specific series of shots. This consistency is reflected in brightness, contrast and color of the images. The key parameters towards capturing consistent images are:
- shutter speed: exposure time set through
shutter_speed
- shooting speed: ISO
- exposure gain: set
exposure_mode
to off and use pragmatic values for eitheranalog_gain
ordigital_gain
- white balance: set
awb_mode
to off and tweak values forawb_gains
This process may require iteration since the hardware characteristics of the camera may differ.
The ISO value for PiCamera v2 ranges from 100 to 1600. Values greater than 800 can be estimated internally when exposure_mode
is set to sports and iso
is set to 0.
The shutter speed is specified in microseconds. If the value is zero then the camera auto exposure process calculates the working shutter speed value.
The exposure mode settings are:
- off
- auto
- night
- nightpreview
- backlight
- spotlight
- sports
- snow
- beach
- verylong
- fixedfps
- antishak
- fireworks
The auto white balance mode settings are:
- off
- auto
- sunlight
- cloudy
- shade
- tungsten
- fluorescent
- incandescent
- flash
- horizon
The command line options for CaptureConsistentImages are (with default values in parentheses):
- -d, --delay (2)
- -i, --iso (100)
- -h, --help
- -h1, --horz (1024)
- -o, --ofile ("../images/CaptureConsistentImages.png")
- -s, --shots (10)
- -v, --vert (768)
-
Capturing time-lapse sequences
-
Capturing in low light
-
Capturing to a network stream
-
Recording video to a file
-
Recording video to a stream
-
Recording over multiple files
-
Recording to a circular stream
-
Recording to a network stream
-
Overlaying images on the preview
-
Overlaying text on the output
-
Controlling the LED
-
Capturing to a numpy array
-
Capturing to an OpenCV object
-
Unencoded image capture in YUV format
-
Unencoded image capture in RGB format
-
Custom outputs
-
Unconventional file outputs
-
Rapid capture and processing
-
Unencoded video capture
-
Rapid capture and streaming
-
Web streaming
-
Capturing images whilst recording
-
Recording at multiple resolutions
-
Recording motion vector data
-
Splitting to/from a circular stream
-
Custom encoders
-
Raw Bayer data captures
-
Using a flash with the camera
- PiCamera release 1.13, Dave Jones https://picamera.readthedocs.io/en/release-1.13/index.html
Prepared for self-paced learning use only.