Main Content

webcam

Connection to 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

webcam

Properties

expand all

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

snapshotCapture RGB image from Camera

Examples

collapse all

You can connect from the MATLAB software to the web camera and take a photograph.

Connect the Raspberry Pi™ to your host computer.

Note

If you have not previously configured your Raspberry Pi, see Install Support for Raspberry Pi Hardware.

Create a connection from the MATLAB software to the Raspberry Pi hardware.

mypi = raspi

Create a connection, wcam, from the MATLAB software to the web camera, and set the image resolution. The connection displays the web camera properties.

wcam = webcam(mypi)
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

Introduced in R2016a