User`s guide

7 Working with Acquired Image Data
7-10
Bringing a Single Frame into the Workspace
To bring a single frame of image data into the MATLAB workspace, use the
getsnapshot function. You can call the getsnapshot function at any time after object
creation.
This example illustrates how simple it is to use the getsnapshot function.
1
Create an image acquisition object — This example creates a video input object
for a Matrox device. To run this example on your system, use the imaqhwinfo
function to get the object constructor for your image acquisition device and substitute
that syntax for the following code.
vid = videoinput('matrox',1);
2
Bring a frame into the workspace — Call the getsnapshot function to bring a
frame into the workspace. Note that you do not need to start the video input object
before calling the getsnapshot function.
frame = getsnapshot(vid);
The getsnapshot function returns an image of the same width and height as
specified by the ROIPosition property and the same number of bands as specified
by the NumberOfBands property. In this example, the video format of the data is
RGB so the value of the NumberOfBands property is 3.
whos
Name Size Bytes Class
frame 96x128x3 36864 uint8 array
vid 1x1 1060 videoinput object
3
Clean up — Always remove image acquisition objects from memory, and the
variables that reference them, when you no longer need them.
delete(vid)
clear vid
For an example of using getsnapshot, see the Image Acquisition Toolbox example
Acquiring a Single Image in a Loop in the Examples list at the top of the
Image Acquisition Toolbox main Documentation Center page, or open the file
demoimaq_GetSnapshot.m in the MATLAB Editor.