Documentation

webcam

Create webcam object to acquire images from Webcams

Syntax

Description

example

cam = webcam creates the webcam object cam and connects to the single Webcam on your system. If you have multiple cameras and you use the webcam function with no input argument, it creates the object and connects it to the first camera it finds listed in the output of the webcamlist function.

When the webcam object is created, it connects to the camera, establishes exclusive access, and starts streaming data. You can then preview the data and acquire images using the snapshot function.

example

cam = webcam(devicenumber) creates a webcam object cam where devicenumber is a numeric scalar value that identifies a particular Webcam by its index number. When you use the webcam function with an index as the input argument, it creates the object corresponding to that index and connects it to that camera.

Note that you cannot create more than one object connected to the same device, and trying to do that generates an error.

example

cam = webcam('cameraname') creates a webcam object cam where cameraname is a character vector value that identifies a particular Webcam by its name. When you use the webcam function with the name of the camera as the input argument, it creates the object and connects it to the camera with that name.

When the webcam object is created, it connects to the camera, establishes exclusive access, and starts streaming data from the camera. You can then preview the data and acquire images using the snapshot function.

Note that you cannot create more than one object connected to the same device, and trying to do that generates an error.

Examples

collapse all

Use the webcam function with no input arguments to create the object and connect it to the first camera it finds. If you only have one camera connected to your system, it connects to that one. If you have multiple cameras, it connects to the first camera listed in the output of the webcamlist function. In the example shown here, it creates the object using the Logitech® camera, since that appears in the webcamlist output first.

Find the name of your camera using the webcamlist function to ensure that MATLAB® is discovering your camera(s).

webcamlist
ans = 

		 'Logitech Webcam 250'
		 'Dell Camera C250'

Create an object, cam.

cam = webcam
cam = 

webcam with properties:

                     Name: 'Logitech Webcam 250'
               Resolution: '640x480'
     AvailableResolutions: {1x11 cell}
                 Exposure: -4
                     Gain: 253
               Saturation: 32
             WhiteBalance: 8240
             ExposureMode: 'auto'
                Sharpness: 48
               Brightness: 128
    BacklightCompensation: 1
                 Contrast: 32

It creates the object and connects it to the Logitech Webcam.

Use the webcam function with an index as the input argument to create the object corresponding to that index and connect it to that camera. If you have multiple cameras connected, index corresponds to the order of cameras in the cell array returned by webcamlist. In the example shown here, device 1 is the Logitech camera and device 2 is the built-in Dell® Webcam.

Find the name of your camera using the webcamlist function to ensure that MATLAB is discovering your camera(s).

webcamlist
ans = 

		 'Logitech Webcam 250'
		 'Dell Camera C250'

Create an object, cam.

cam = webcam(2)
cam = 

webcam with properties:

                Name: 'Dell Camera C250'
          Resolution: '320x240'
AvailableResolutions: ('320x240' '160x120' '80x60')
          Brightness: 128
            Contrast: 32
                Gain: 0

It creates the object and connects it to the Dell Webcam. If you only have one camera, you do not need to use the index.

Use the webcam function with the name of the camera as the input argument to create the object and connect it to the camera with that name.

Find the name of your camera using the webcamlist function to ensure that MATLAB is discovering your camera(s).

webcamlist
ans = 

		 'Logitech Webcam 250'
		 'Dell Camera C250'

Create an object, cam. You can use the exact name from the output of webcamlist, which is 'Logitech Webcam 250' in this example. Or you can also use a shortened version of the name, for example, the brand of the camera, which in this case is 'Logitech'.

cam = webcam('Logitech')
cam = 

webcam with properties:

                     Name: 'Logitech Webcam 250'
               Resolution: '640x480'
     AvailableResolutions: {1x11 cell}
                 Exposure: -4
                     Gain: 253
               Saturation: 32
             WhiteBalance: 8240
             ExposureMode: 'auto'
                Sharpness: 48
               Brightness: 128
    BacklightCompensation: 1
                 Contrast: 32

It creates the object and connects it to the Logitech Webcam.

Related Examples

Input Arguments

collapse all

Device number of your hardware, specified as a numeric scalar. This number identifies a particular Webcam by its index number. It creates the object corresponding to that index and connects it to that camera. The index corresponds to the order of cameras in the cell array returned by webcamlist when you have multiple cameras connected.

Example: cam = webcam(2)

Data Types: double

Name of your camera, specified as a character vector. This argument creates a webcam object cam where cameraname is a character vector value that identifies a particular Webcam by its name. When you use the webcam function with the name of the camera as the input argument, it creates the object and connects it to the camera with that name. You can use the exact name that is returned by the webcamlist function, such as 'Logitech Webcam 250'. You can also use a shortened version of the name, for example, the brand of the camera. In this example you could simply use 'Logitech' and it connects to the Logitech Webcam.

Example: cam = webcam('Logitech')

Data Types: char

Introduced in R2014a

Was this topic helpful?