configuring callback properties -凯发k8网页登录
this example explains how callback functions work and shows how to use them.
callback functions are executed when an associated event occurs. to configure a callback to execute for a particular event, configure one of the video input object's callback properties:
errorfcn
framesacquiredfcn
startfcn
stopfcn
timerfcn
triggerfcn
this tutorial uses a callback function that displays the n'th frame, where n is provided as an input argument to the callback function.
select a device to use for acquisition and configure it to acquire data upon executing a manual trigger.
% access an image acquisition device. vidobj = videoinput('winvideo', 1); % acquire an infinite number of frames when manually triggered. triggerconfig(vidobj, 'manual'); vidobj.framespertrigger = inf;
configure the video input object to execute a callback function when the acquisition is stopped.
% specify the n'th frame the callback function will display. framenumber = 3; % have the callback function executed when the acquisition ends. vidobj.stopfcn = {'util_showframe', framenumber}; % initiate the acquisition. start(vidobj)
upon triggering the image acquisition device, a tennis ball is dropped within the camera's view.
% trigger the object for logging and acquire data for a few seconds.
trigger(vidobj)
pause(5);
when the acquisition is stopped, it will cause the callback function to execute and display the n'th frame.
% stop the acquisition.
stop(vidobj)
once the video input object is no longer needed, delete it and clear it from the workspace.
delete(vidobj)
clear vidobj