This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Configuring Callback Properties

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, found in the

  • MATLABROOT\toolbox\imaq\imaqdemos\helper

directory, 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.

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.

When the acquisition is stopped, it will cause the callback function to execute and display the N'th frame.

% Stop the acquisition.

Once the video input object is no longer needed, delete it and clear it from the workspace.

clear vidobj