Use the snapshot
function to acquire one image frame from a webcam. You then show it using a display function such as imshow
or image
.
Find the name of your camera using the webcamlist
function to ensure that MATLAB® is discovering your camera(s).
ans = 2×1 cell array
{'Logitech Webcam 250' }
{'Microsoft® LifeCam Cinema(TM)'}
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. 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'
. Use cam
as the name of the object.
cam =
webcam with properties:
Name: 'Logitech Webcam 250'
Resolution: '640x480'
AvailableResolutions: {'640x480' '160x90' '160x100' '160x120' '176x144' '320x180' '320x200' '320x240' '352x288' '640x360' '640x400'}
Exposure: -6
Sharpness: 48
Gain: 63
Saturation: 32
BacklightCompensation: 1
Brightness: 128
WhiteBalance: 0
Contrast: 32
ExposureMode: 'auto'
It creates the object and connects it to the Logitech® webcam.
Preview the image from the webcam.
The preview window opens and displays live video stream from your camera. The preview dynamically updates, so if you change a property while previewing, the image changes to reflect the property change.
Close the preview.
The preview window closes.
Acquire a single image from the camera using the snapshot
function and assign it to the variable img
.
Display the acquired image.
You can also use the image
function to display the acquired image.
Clean up by clearing the object.