webcam - Connection to USB web camera - MATLAB (original) (raw)
Main Content
Connection to USB web camera
Description
This object represents a connection from the MATLAB® software to a web camera attached to the NVIDIA DRIVE® or Jetson™ hardware. To create this object, use the webcam function. To configure the web camera settings, use the object properties listed in Properties. To interact with the web camera, use this object with the functions listed in Object Functions.
Creation
Syntax
Description
[wcam](#mw%5Fe9061b74-1cff-4406-a3d5-ca58286952f3) = webcam([hwObj](#mw%5F4d864cec-f910-40eb-862d-b786bd069531%5Fsep%5Fmw%5Fbcc65819-faa5-4997-9bca-35a8da7d894a))
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](#mw%5Fe9061b74-1cff-4406-a3d5-ca58286952f3) = webcam([hwObj](#mw%5F4d864cec-f910-40eb-862d-b786bd069531%5Fsep%5Fmw%5Fbcc65819-faa5-4997-9bca-35a8da7d894a),[cameraName](#mw%5Fa3da1c92-b843-480d-8441-9f4416326c67))
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](#mw%5Fe9061b74-1cff-4406-a3d5-ca58286952f3) = webcam([hwObj](#mw%5F4d864cec-f910-40eb-862d-b786bd069531%5Fsep%5Fmw%5Fbcc65819-faa5-4997-9bca-35a8da7d894a),[cameraIndex](#mw%5F580a12e4-26f0-47cd-87bd-26d6efe0951a))
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](#mw%5Fe9061b74-1cff-4406-a3d5-ca58286952f3) = webcam([hwObj](#mw%5F4d864cec-f910-40eb-862d-b786bd069531%5Fsep%5Fmw%5Fbcc65819-faa5-4997-9bca-35a8da7d894a),[cameraName](#mw%5Fa3da1c92-b843-480d-8441-9f4416326c67),[resolution](#mw%5F10d2a1c1-68f1-4087-8c7d-50c23d48d25a))
allows you to select the dimensions of the image captured 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 theclear function.
Input Arguments
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 character vector. This optional argument identifies a particular camera by its name. You can use the value of the WebcamList
property of the hardware object, such as 'Microsoft LifeCam VX-2000'
Index of the camera attached to the target hardware, specified as a positive integer. This optional argument identifies a particular camera by its index number.
The height and width of the image in pixels that the camera captures, specified as a character vector. Use the AvailableResolutions
property of thewcam
object to get a cell array of the available resolutions for your camera.
Output Arguments
Connection to a web camera that is attached to the NVIDIA DRIVE or Jetson hardware.
You can use wcam
with the following snapshot function.
Properties
This property is read-only.
Image dimensions, specified as a string.
Example: '640x480'
Data Types: char
This property is read-only.
Image dimensions, specified as a cell array of strings.
When you create the webcam object, you can specify this value.
Example: {'320x240' '640x480'}
Data Types: char
Object Functions
Examples
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 thehwobj
object.
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 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 thewcam
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
Extended Capabilities
Version History
Introduced in R2018b
See Also
Functions
Objects
- jetson | drive | imageDisplay | camera
Topics
- Sobel Edge Detection on NVIDIA Jetson Nano Using Raspberry Pi Camera Module V2
- Getting Started with the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms
- Deploy and Run Sobel Edge Detection with I/O on NVIDIA Jetson Nano
- Build and Run an Executable on NVIDIA Hardware
- Stop or Restart an Executable Running on NVIDIA Hardware
- Run Linux Commands on NVIDIA Hardware