Starting and Stopping a Video Input Object
When you create a video input object, you establish a connection
between MATLAB® and an image
acquisition device. However, before you can acquire data from the
device, you must start the object, using the
When you start an object, you reserve the device for your exclusive use and lock the configuration. Thus, certain properties become read only while running.
An image acquisition object stops running when any of the following conditions is met:
The requested number of frames is acquired. This occurs when
FramesAcquired = FramesPerTrigger * (TriggerRepeat + 1)
TriggerRepeatare properties of the video input object. For information about these properties, see Acquiring Image Data.
A run-time error occurs.
Timeoutvalue is reached.
You issue the
When an object is started, the toolbox sets the object's
'on'. When an object is not running, the toolbox
sets the object's
Running property to
this state is called stopped.
The following figure illustrates how an object moves from a running to a stopped state.
Transitions from Running to Stopped States
The following example illustrates starting and stopping an object:
Create an image acquisition object — This example creates a video input object for a webcam image acquisition device. To run this example on your system, use the
imaqhwinfofunction to get the object constructor for your image acquisition device and substitute that syntax for the following code.
vid = videoinput('winvideo',1);
Verify that the image is in a stopped state — Use the
isrunningfunction to determine the current state of the video input object.
isrunning(vid) ans = 0
Configure properties To illustrate object states, set the video input object's
'Manual'. To set the value of certain trigger properties, including the
TriggerTypeproperty, you must use the
triggerconfigfunction. See Setting the Values of Trigger Properties for more information.
Configure an acquisition that takes several seconds so that you can see the video input in logging state.
vid.FramesPerTrigger = 100;
Start the image acquisition object — Call the
startfunction to start the image acquisition object.
Verify that the image is running but not logging — Use the
isloggingfunctions to determine the current state of the video input object. With manual triggers, the video input object is in running state after being started but does not start logging data until a trigger executes.
isrunning(vid) ans = 1 islogging(vid) ans = 0
Execute the manual trigger — Call the
triggerfunction to execute the manual trigger.
While the acquisition is underway, check the logging state of the video input object.
islogging(vid) ans = 1
After it acquires the specified number of frames, the video input object stops running.
isrunning(vid) ans = 0
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