webcam - Create connection to Raspberry Pi web camera - MATLAB (original) (raw)
Create connection to Raspberry Pi web camera
Description
This object represents a connection from the MATLAB® software to a web camera attached to the Raspberry Pi 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
Description
`wcam` = webcam([mypi](#bu6ial4%5Fsep%5Fshared-mypi))
creates a connection, wcam
, from the MATLAB software to a web camera that is attached the Raspberry Pi® hardware. You can capture still images by using_wcam
_ with the snapshot
function.
`wcam` = webcam([mypi](#bu6ial4%5Fsep%5Fshared-mypi), [cameraName](#mw%5F336f7c62-0a66-402c-8516-d19b44bba0f0))
allows you to select the camera specified by cameraName
. Use this syntax when you have more than one camera connected to the Raspberry Pi hardware.
`wcam` = webcam([mypi](#bu6ial4%5Fsep%5Fshared-mypi), [cameraIndex](#mw%5F79eccac7-49ce-4336-8798-a2aff1a1caeb))
allows you to select the camera specified by cameraIndex
. Use this syntax when you have more than one camera connected to the Raspberry Pi hardware.
`wcam` = webcam([mypi](#bu6ial4%5Fsep%5Fshared-mypi), [cameraName](#mw%5F336f7c62-0a66-402c-8516-d19b44bba0f0), [resolution](#mw%5Fcbc8b857-a504-4e84-8fee-88034a3e5a67))
allows you to select the dimensions of the image taken by the camera connected to the Raspberry Pi hardware.
Input Arguments
Connection to the Raspberry Pi hardware board, specified as a raspi object.
Name string of camera. Optional.
Index of camera. Optional.
String of image dimensions. Optional.
If you do not know the resolutions supported by your camera:
- Create a connection,
wcam
, using this syntax. The connection displays the supported resolutions in theAvailableResolutions
property. Note the resolutions displayed. - Clear the
wcam
object. - Recreate the
wcam
object. Provide any of the noted resolutions as input argument.
wcam = webcam(mypi, cameraName, '160x120')
Properties
This property is read-only.
Name of your webcam, specified as a character vector. It is specific to each camera.
Example: '/dev/video0'
Data Types: char
Resolution of captured image, specified as a character vector.
Example: '320x240'
Data Types: char
This property is read-only.
Resolutions available on your webcam, specified as a cell array of character vectors.
Example: {'320x240' '640x480'}
Data Types: cell
Object Functions
snapshot | Capture latest RGB image frame from Camera Board or selected camera on ArduCam Multi Camera Adapter Module |
---|---|
readFrame | Return oldest image frame from board, web, or ArduCam module camera |
Examples
You can connect from the MATLAB software to the USB web camera connected to Raspberry Pi board and take a photograph.
Create a connection from the MATLAB to the Raspberry Pi board. If you encounter errors after running the above command, try using additional arguments (as listed in raspi) or refer to Troubleshoot Connecting Issues to Raspberry Pi Hardware.
Create a connection from the MATLAB software to the Raspberry Pi hardware.
Create a connection, wcam
, from the MATLAB software to the USB web camera connected to the Raspberry Pi board, and set the image resolution. The connection displays the web camera properties.
wcam =
webcam with properties:
Name: "/dev/video0"
Resolution: "320x240"
AvailableResolutions: {"320x240" "640x480"}
Import and display a sequence of 10 snapshots on your host computer.
for ii = 1:10 img = snapshot(wcam); imagesc(img) drawnow end
Extended Capabilities
Usage notes and limitations:
The
webcam
object accepts resolution as a string only if the resolution value specified matches any of these values:'160x120'
,'320x240'
,'640x480'
,'800x600'
,'1024x768'
,'1280x720'
, or'1920x1080'
. To set the resolution to any other value, specify the value in the[width height]
format, for example,[640 240]
. For any run-time error, analyze the associated log file.The
AvailableWebcams
property is a dynamically populated cell array and cannot be used for code generation.You can also deploy the
webcam
object on the Raspberry Pi hardware in MATLAB Online™.Using the full version of the Raspberry Pi OS is recommended when deploying
webcam
on the Raspberry Pi hardware in MATLAB Online.
Version History
Introduced in R2016a