メインコンテンツ

camera

R2026b

Connection to USB or CSI camera

Description

Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

The camera object represents a connection from the MATLAB® software to a web camera attached to the NVIDIA DRIVE® or Jetson™ hardware. To obtain the list of cameras connected to the hardware, use the getCameraList function. Connect to the camera by creating a camera object. To take a snapshot with the camera, use the snapshot function.

Creation

Description

cam = camera(hwObj,cameraName,resolution) connects to the camera with the name cameraName on the NVIDIA DRIVE or Jetson hardware and returns the connection object cam. The camera uses the resolution resolution to capture snapshots.

You can connect to a camera connected to the USB and camera peripheral interfaces (CSI) of the target board. When you create a camera object, MATLAB establishes exclusive access to stream data.

Note

You cannot associate more than one object to the same camera. Before code generation and execution, you must clear the camera object by using the clear function.

example

cam = camera(___,Name=Value) creates a connection to the camera by using one or more name-value arguments. For example, to set the pixel format that the camera uses, specify the "PixelFormat" argument.

example

Input Arguments

expand all

Connection to a specific NVIDIA hardware board, specified as a jetson or drive object.

Name of the camera attached to the target hardware, specified as a string or character vector. To obtain the name of the camera, use the getCameraList function. For example, getCameraList outputs the name "Microsoft LifeCam VX-2000" for a Microsoft® camera.

This argument sets the Name property.

Resolution of the image, in pixels, that the camera captures, specified as a 1-by-2 numeric array. To get a list of resolutions for the camera connected to the board, use the getCameraList function. You can specify height and width values that are multiples of the resolutions supported by the camera.

Note

On NVIDIA targets, the CSI drivers do not support odd pixel values for the resolution.

This argument sets the ImageSize property.

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Linux device ID of the camera, specified as a string or character vector. If your target hardware uses multiple cameras with the same name, specify the camera by using the VideoDevice argument. See Connect to Camera Using Device ID.

This argument sets the VideoDevice property.

Example: camera(hwObj,"vi-output, ov5693 2-0036",[2592 1944],VideoDevice="/dev/video0")

Frame format for the camera, specified as "BG10", "MJPG, or "YUYV".

This argument sets the PixelFormat property.

Example: camera(hwObj,"vi-output, ov5693 2-0036",[2592 1944],PixelFormat="MJPG")

Output Arguments

expand all

Connection to the web camera, returned as a camera object.

Properties

expand all

This property is read-only.

Camera name, represented as a character vector.

Example: 'vi-output, ov5693 2-0036'

This property is read-only.

Dimensions, in pixels, of the image from the camera, represented as a 1-by-2 numeric array.

Example: [2592 1944]

This property is read-only.

Linux device number of the camera, represented as a character vector.

Example: '/dev/video0'

This property is read-only.

Frame format for the camera, represented as 'BG10', 'MJPG', or 'YUYV'.

Object Functions

snapshotCapture RGB image from Camera

Examples

collapse all

You can connect to the CSI camera connected to an NVIDIA platform and capture images from the camera.

Create a live hardware connection from MATLAB to the NVIDIA hardware by using the jetson function.

hwObj = jetson;

To find the camera name, use the getCameraList function. The function returns a table with the camera names, device IDs, available resolutions, and available formats.

camlist = getCameraList(hwObj);
              Camera Name              Video Device     Available Resolutions    Pixel Formats
    _______________________________    _____________    _____________________    _____________

    "Microsoft LifeCam Cinema(TM):"    "/dev/video0"    "(View resolutions)"      "YUYV,MJPG" 

To determine the available resolutions, click the View Resolutions link in the Available Resolutions column. This code shows a snippet of the output from the link.

Resolutions: [160 120],[176 144],[320 240],[352 288],[416 240],[424 240],[640 360],...

Create a camera object by using the name of the camera from the list and a supported resolution.

camObj = camera(hwObj,"Microsoft LifeCam Cinema(TM):",[1280 720])
camObj = 

  camera with properties:

            Map: [1×1 containers.Map]
           Name: 'Microsoft LifeCam Cinema(TM):'
      ImageSize: [1280 720]
    VideoDevice: '/dev/video0'
    PixelFormat: "YUYV"

Capture a frame from the camera by using the snapshot function.

img = snapshot(cam);
figure();
imagesc(img);
drawnow;

Desk with a pyramid on top of it. The pyramid says "Thanks" and contains an image of an L-shaped membrane

If you have multiple cameras with the same name, you can use the device ID to select a specific camera. For example, suppose that you have a jetson object, hwObj. Get the list of cameras connected to the board by using the getCameraList function. In the table, the Video Device column shows the device ID for the corresponding camera.

camlist = getCameraList(hwobj);
              Camera Name              Video Device     Available Resolutions    Pixel Formats
    _______________________________    _____________    _____________________    _____________

    "Microsoft LifeCam Cinema(TM):"    "/dev/video0"    "(View resolutions)"      "YUYV,MJPG" 
    "Microsoft LifeCam Cinema(TM):"    "/dev/video1"    "(View resolutions)"      "YUYV,MJPG" 

Connect to the second camera. Specify the device ID by using the VideoDevice argument.

camObj = camera(hwObj,"Microsoft LifeCam Cinema(TM)",resolution,VideoDevice="/dev/video1");

To determine the available pixel formats for your camera, use the getCameraList function. The Pixel Format column lists the available pixel formats. In this example, the function shows that the camera can use the "YUYV" or "MJPG" formats.

camlist = getCameraList(hwObj);
              Camera Name              Video Device     Available Resolutions    Pixel Formats
    _______________________________    _____________    _____________________    _____________

    "Microsoft LifeCam Cinema(TM):"    "/dev/video0"    "(View resolutions)"      "YUYV,MJPG" 

Create a camera object that uses the "MJPG" format.

camObj = camera(hwObj,"Microsoft LifeCam Cinema(TM)",resolution,PixelFormat="MJPG");

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2019a

expand all