User`s guide

Bringing Image Data into the MATLAB Workspace
7-5
Acquiring 10 Seconds of Image Data
This example shows how you can configure an approximate time-based acquisition using
the FramesPerTrigger property:
1
Create an image acquisition object — This example creates a video input object
for a Windows image acquisition 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('winvideo',1);
2
Configure properties — To acquire 10 seconds of data, determine the frame rate
of your image acquisition device and then multiply the frame rate by the number of
seconds of data you want to acquire. The product of this multiplication is the value of
the FramesPerTrigger property.
For this example, assume a frame rate of 30 frames per second (fps). Multiplying 30
by 10, you need to set the FramesPerTrigger property to the value 300.
vid.FramesPerTrigger = 300;
3
Start the image acquisition object — Call the start function to start the image
acquisition object.
start(vid)
The object executes an immediate trigger and begins acquiring frames of data. The
start function returns control to the command line immediately but the object
continues logging the data to the memory buffer. After logging the specified number
of frames, the object stops running.
4
Bring the acquired data into the workspace — To verify that you acquired
the amount of data you wanted, use the optional getdata syntax that returns the
timestamp of every frame acquired. The difference between the first timestamp and
the last timestamp should approximate the amount of data you expected.
[data time] = getdata(vid,300);
elapsed_time = time(300) - time(1)
10.0467
5
Clean up — Always remove image acquisition objects from memory, and the
variables that reference them, when you no longer need them.