camera - Connection to USB or CSI camera - MATLAB (original) (raw)
Connection to USB or CSI 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 camera 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
[cam](#mw%5F2794e80c-1f2c-4897-bc79-bafd793b65a8) = camera([hwObj](#mw%5Ff09e7563-39cd-472d-9fab-660055854437%5Fsep%5Fmw%5Fbcc65819-faa5-4997-9bca-35a8da7d894a),[cameraName](#mw%5Fc253e712-8051-4d43-9baf-71bb30f53791),[resolution](#mw%5Fe8b3d1ac-8847-422e-956f-7f09d73338c0))
creates a camera
object cam
and connects to a camera that is attached to the NVIDIA DRIVE or Jetson hardware. The camera
function supports cameras connected to USB and camera peripheral interfaces (CSI) of the target board. When thecamera
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.
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 camera
object by using theclear function.
The CSI drivers on the NVIDIA® target do not support odd pixel values for the resolution.
[cam](#mw%5F2794e80c-1f2c-4897-bc79-bafd793b65a8) = camera(___,'VideoDevice',['VideoDeviceID'](#mw%5F55b1f62e-5c6d-4ec7-84d9-26a5051c3637))
creates a camera
object cam
and connects to a camera by using Linux® device number. If your target hardware is connected to multiple cameras with the same name, use the 'VideoDevice'
argument to specify the camera to create a connection to.
[cam](#mw%5F2794e80c-1f2c-4897-bc79-bafd793b65a8) = camera(___,'PixelFormat',['Format'](#mw%5Fb87d97a3-4197-40ac-b9c8-e3ae6c92e882))
creates a camera
object cam
specifying the frame format of the incoming data.
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 string or character vector. This argument identifies a particular camera by its name. You can use the exact name that is returned by the getCameraList
function, such as 'Microsoft LifeCam VX-2000'
The height and width of the image in pixels that the camera captures, specified as a 1-by-2 numeric array. Use the getCameraList
function to get a list of the Available Resolutions
supported by the cameras connected to the target board. You can specify height and width values that are multiples of the resolutions supported by the camera. The CSI drivers on the NVIDIA target do not support odd pixel values for the resolution.
Create a camera
object by using the Linux device number of the camera, specified as a character vector. If your target hardware is connected to multiple cameras with the same name, use the'VideoDevice'
argument along with a value to identify the camera to create the connection to. Use the getCameraList
function to get the Video Device
number of the cameras connected to the target board.
Example: camera(hwObj,"vi-output, ov5693 2-0036",[2592 1944],'VideoDevice','/dev/video0')
Specify the format of the frames from the camera.
Example: camera(hwObj,"vi-output, ov5693 2-0036",[2592 1944],'PixelFormat','MJPG')
Output Arguments
Connection to a camera that is attached to the NVIDIA DRIVE or Jetson hardware. To capture images from the camera, use thecam
object with the snapshot function.
Properties
This property is read-only.
Camera name, returned as a character vector.
Example: 'vi-output, ov5693 2-0036'
This property is read-only.
The height and width of the image in pixels that the camera captures, returned as a 1-by-2 numeric array.
Example: [2592 1944]
This property is read-only.
This property is read-only.
The Linux device number of the camera, returned as a character vector.
Example: '/dev/video0'
Object Functions
Examples
You can connect from the MATLAB software to the onboard CSI 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 camera name, use the getCameraList
function.
camlist = getCameraList(hwobj)
camlist =
2×3 table
Camera Name Video Device Available Resolutions
______________________________ _____________ ____________________________________
"vi-output, ov5693 2-0036" "/dev/video0" "[1280 720],[2592 1458],[2592 1944]"
"Microsoft LifeCam Cinema(TM)" "/dev/video1" "(View resolutions)"
If the function does not list a USB based camera, try reconnecting the USB webcam and run the updatePeripheralInfo function. This function tries to scan the available webcams on the target when there is an addition or deletion.
updatePeripheralInfo(hwobj);
Create a camera object, cam
using the name of the camera from the list and a supported resolution. For multiple cameras with the same name, use the 'VideoDevice'
argument to identify a camera by its Linux device number. The cam
object has the following camera properties.
cam = camera(hwobj,"vi-output, ov5693 2-0036",[2592 1944])
cam =
camera with properties:
Name: 'vi-output, ov5693 2-0036'
ImageSize: [2592 1944]
VideoDevice: '/dev/video0'
To capture a frame of image from this camera and display it in MATLAB, use the following commands.
img = snapshot(cam); figure(); imagesc(img); drawnow;
To change the resolution of the image capture, you must clear thecamera
object by using the clear function and then use thecamera
function to connect to the camera again.
clear cam; cam = camera(hwobj,"vi-output, ov5693 2-0036",[1280 720]);
Extended Capabilities
Version History
Introduced in R2019a
See Also
Functions
Objects
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