主要内容

Raspberry Pi Camera Video Capture

R2026b

Capture live video from Raspberry Pi CSI camera module

Since R2026b

  • Raspberry Pi camera module connected via the CSI interface

Libraries:
Raspberry Pi Blockset / Audio and Video

Description

The Raspberry Pi Camera Video Capture block captures video frames from a camera serial interface (CSI) on Raspberry Pi® hardware and outputs the image data as separate color panes. Use this block to capture live camera data within your Simulink® model for vision and image processing workflows on Raspberry Pi hardware.

Tune the camera output for your application using the image and device controls such as brightness, contrast, saturation, sharpness, exposure mode and compensation, white balance mode, metering mode, rotation, and region of interest (ROI).

During simulation, the block outputs a moving test-pattern image to support model development without hardware. When you run the model on Raspberry Pi, the block captures live video frames from the connected CSI camera module.

Note

To generate C/C++ code for this block, you must have an Embedded Coder® license.

Examples

expand all

This example shows how to capture live video from a Raspberry Pi CSI‑connected camera module using thee Raspberry Pi Camera Video Capture block and display the video frames in Simulink.

Create a new Simulink model and add the Raspberry Pi Camera Video Capture block from the Raspberry Pi Blockset > Audio and Video library.

Open the block parameter dialog box. Set Image size to 640x480 and Pixel format to RGB.

Set Sample time to 0.1 to capture frames at 10 frames per second (fps).

Add three Display (Simulink) blocks to the model. Connect the R, G, and B output ports of the Raspberry Pi Camera Video Capture block to the three Display blocks, respectively.

Simulink model with a Raspberry Pi Camera Video Capture block connected to three output ports representing the red (R), green (G), and blue (B) image components.

On the Hardware tab of the model, set the hardware board to your target device and configure the device address. In the Mode section, select Connected IO and then click Run with IO. Observe the live camera feed.

This example shows how to adjust image properties such as brightness and exposure for a Raspberry Pi CSI camera using the Raspberry Pi Camera Video Capture block.

Create a new Simulink model and add the Raspberry Pi Camera Video Capture block from the Raspberry Pi Blockset > Audio and Video library.

Open the block parameter dialog box. Set Image size to 640x480 and Pixel format to RGB.

Add three Display (Simulink) blocks to the model. Connect the R, G, and B output ports of the Raspberry Pi Camera Video Capture block to the three Display blocks, respectively.

Simulink model with a Raspberry Pi Camera Video Capture block connected to three output ports representing the red (R), green (G), and blue (B) image components.

Open the Advanced tab of the block parameters. In the Device properties section, set Exposure mode to Normal and adjust Exposure mode compensation to 0.7 to brighten the image.

Set AWB mode to Daylight to optimize white balance for outdoor lighting conditions.

On the Hardware tab of the model, in the Mode section, select Connected IO and then click Run with IO. Observe the live camera feed. While the model runs, adjust the Brightness, Contrast, Saturation, and Sharpness sliders in the block dialog box to observe changes in real time.

This example shows how to use the Flip image along horizontal axis and Flip image along vertical axis parameters to mirror an image horizontally and vertically by observing how pixel positions change from input to output. The following example uses a simplified 2x2 image where, each letter represents a pixel position.

This diagram shows how the block flips the input image along the vertical axis. The image pixels in each row swap positions from left to right, while row positions remain unchanged.

Diagram showing horizontal flip of a 2×2 image. The input image displays A at top-left, B at top-right, C at bottom-left, and D at bottom-right. After horizontal flip, the output image shows B at top-left, A at top-right, D at bottom-left, and C at bottom-right, illustrating left-to-right mirroring of pixel positions.

This diagram shows how the block flips the input image along the horizontal axis. The image rows swap positions from top to bottom, while column positions remain unchanged.

Diagram showing vertical flip of a 2×2 image. The input image displays A at top-left, B at top-right, C at bottom-left, and D at bottom-right. After vertical flip, the output image shows C at top-left, D at top-right, A at bottom-left, and B at bottom-right, illustrating top-to-bottom mirroring of pixel positions.

Extended Examples

Ports

Output

expand all

The block outputs the red component of each pixel.

Dependencies

  • To enable this port, set Pixel format to RGB.

Data Types: uint8

The block outputs the green component of each pixel.

Dependencies

  • To enable this port, set Pixel format to RGB.

Data Types: uint8

The block outputs the blue component of each pixel.

Dependencies

  • To enable this port, set Pixel format to RGB.

Data Types: uint8

The block outputs the luma component of each pixel.

Dependencies

  • To enable this port, set Pixel format to YCbCr 4:2:0.

Data Types: uint8

The block outputs the blue difference component of each pixel.

Dependencies

  • To enable this port, set Pixel format to YCbCr 4:2:0.

Data Types: uint8

The block outputs the red difference component of each pixel.

Dependencies

  • To enable this port, set Pixel format to YCbCr 4:2:0.

Data Types: uint8

Parameters

expand all

Basic

Specify index of the CSI camera module connected to the Raspberry Pi hardware. Use this parameter when multiple camera modules are available.

Select the output resolution for captured video frames. Use a predefined resolution for compatibility across camera modules. Select Custom to define an image resolution size not listed in the drop-down.

Specify the output resolution as a two‑element vector [width height]. Use this parameter when predefined resolutions do not meet application requirements.

Dependencies

  • To enable this parameter, set Image size to Custom.

Select the color format for output data.

  • RGB — Outputs red, green, and blue components.

  • YCbCr 4:2:0 — Outputs luminance and chrominance components.

The selected format determines the available output ports.

Specify the time interval, in seconds, at which the block captures video frames. Lower values increase the frame capture rate.

Select the parameter to flip the image along its vertical reference. For more information, see Flip image vertically and horizontally.

Select the parameter to flip the image along its horizontal reference. For more information, see Flip image vertically and horizontally.

Advanced

Select how the camera controls exposure during image capture. Use this parameter to automatically adjust exposure dynamically based on scene lighting.

  • Normal — This mode balances exposure for general purpose scenes.

  • Sport — This mode works best for scenes with shorter exposure times to reduce motion blur.

Specify an offset that increases or decrease the exposure relative to the selected exposure mode.

Select how the camera evaluates scene brightness for exposure. The mode you select determines which regions of the image contribute most to exposure calculation.

Adjust the brightness of the captured image. Larger values increase overall image brightness while smaller values reduce it.

Adjust the intensity of colors in the captured image. Lower values reduce color intensity and higher values increase it.

Adjust the contrast of the captured image by modifying the difference between light and dark regions.

Adjust the sharpness of edges and fine details in the captured image.

Rotate the captured image by the specified angle.

Select from the different white balancing modes to allow the camera to compensate for lighting conditions.

Extended Capabilities

expand all

Version History

Introduced in R2026b