Main Content

snapshot

Capture RGB image from Camera

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

Description

img = snapshot(cam) returns a still image in RGB format from the camera specified in the cam object.

example

[img,ts] = snapshot(cam) returns a still image in RGB format and the time stamp of the capture from the camera specified in the cam object.

example

Examples

collapse all

You can connect from the MATLAB® software to a USB camera connected to an NVIDIA® platform and capture images from this camera.

Create a live hardware connection from the MATLAB software to the NVIDIA hardware by using the jetson function. To create a live hardware connection object, provide the host name or IP address, user name, and password of the target board. For example:

hwobj = jetson('jetson-board-name','ubuntu','ubuntu');

To find the web camera name, check the webcamlist property of the hwobj object.

hwobj.webcamlist
ans =

  1×1 cell array

    {'Microsoft® LifeCam Cinema(TM)'}

If this property is empty, then try reconnecting the USB webcam and run the following command. This command tries to scan the available webcams on the target when there is a addition or deletion.

updatePeripheralInfo(hwobj);

Create a webcam object, wcam using the name or the index number of the webcam list. If a webcam name or the index is not specified, then it uses the default webcam. The wcam object has the following camera properties.

wcam = webcam(hwobj)
wcam = 

  webcam with properties:

                    Name: 'Microsoft® LifeCam Cinema(TM)'
              Resolution: '320x240'
    AvailableResolutions: {1×12 cell}

To display the images captured from webcam in MATLAB, use the following commands.

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

To change the resolution of the image capture, use the following command.

clear wcam;
wcam = webcam(hwobj,1,[1280 800])

You can use the AvailableResolutions property of the wcam object to get a cell array of the available resolutions for your camera.

Import and display a sequence of 50 snapshots on your host computer.

figure();
for ii = 1:50
    img = snapshot(wcam);
    imagesc(img);
    drawnow;
end

Input Arguments

collapse all

Connection to a camera, specified as a camera or webcam object.

Example: mycam

Output Arguments

collapse all

RGB image, returned as an m-by-n-by-3 numeric array with values in the range [0,255].

Data Types: uint8

Timestamp of the snapshot, returned as a datetime object.

Extended Capabilities

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 R2018b