This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

webcam

Create webcam object to acquire images from a webcam attached to the NVIDIA DRIVE or Jetson hardware

Syntax

wcam = webcam(hwObj)
wcam = webcam(hwObj,cameraName)
wcam = webcam(hwObj,cameraIndex)
wcam = webcam(hwObj,cameraName,resolution)

Description

example

wcam = webcam(hwObj) creates a webcam object wcam and connects to a web camera that is attached to the NVIDIA® DRIVE or Jetson hardware. When the webcam object is created, it connects to the camera and establishes exclusive access to stream data. You can preview the data and acquire images by using the snapshot function.

wcam = webcam(hwObj,cameraName) allows you to select the camera specified by cameraName. Use this syntax when you have more than one camera connected to the NVIDIA hardware.

wcam = webcam(hwObj,cameraIndex) allows you to select the camera specified by cameraIndex. Use this syntax when you have more than one camera connected to the NVIDIA hardware.

wcam = webcam(hwObj,cameraName,resolution) allows you to select the dimensions of the image taken by the camera connected to the NVIDIA hardware.

Note

Because the software establishes exclusive access to the camera, you cannot associate more than one object to the same camera. Before code generation and execution, you must clear the webcam object by using the clear function.

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('192.168.1.15','ubuntu','ubuntu');

Check the webcamlist property of the hwobj object to find the web camera name.

hwobj.webcamlist
ans =

  1×1 cell array

    {'Microsoft® LifeCam Cinema(TM)'}

If this property is empty, then try re-connecting 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.

hwobj.updatePeripheralInfo;

Create a webcam object, wcam using the name or the index number of the webcam list. If no webcam name or the index is 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 specific NVIDIA hardware board, specified as a jetson or drive object.

Use the jetson or the drive function to create this connection.

Name string of camera. Optional.

Index of camera. Optional.

Array of image dimensions. Optional.

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

Output Arguments

collapse all

Connection to a web camera that is attached to the NVIDIA Drive or Jetson hardware.

You can use wcam with the following snapshot function.

Introduced in R2018b