webcam

Create connection to Raspberry Pi web camera

Description

wcam = webcam(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, cameraName) 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, cameraIndex) 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, cameraName, resolution) allows you to select the dimensions of the image taken by the camera connected to the Raspberry Pi hardware.

Input Arguments

collapse all

Connection to a specific Raspberry Pi hardware board, specified as a raspi object.

Name string of camera. Optional.

Index of camera. Optional.

String 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 Raspberry Pi web camera.

You can use wcam with the following snapshot function.

Examples

Use the Web Camera

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 Update Support Package.

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

Extended Capabilities