How can I store an object when using timer function?

1 view (last 30 days)
I am trying to implement a real time foreground analysis system. I am using 'timer' function to call the foreground analysis function at a given period to achieve it. Since the foreground analysis function requires certain amount of images/frames to identify the foreground, the prior information needs to be stored. (I created an object using vision.ForegroundDetector and the prior information should be stored in this object.) I tried to store this object in 'userData' and let the callback function use/update it. However, the foreground detector didn't detect anything. I am guessing the 'UserData' cannot take an object data, but I am not sure. Can anyone help me solve the problem? Thanks.
The code of the timer function and image analysis function are attached below:
(vid is the video acquired by matlab image acquasition toolbox.)
TimerData=timer('TimerFcn',{@FrameRateDisplay,vid,se},'Period',1/NumberFrameDisplayPerSecond,'ExecutionMode','fixedRate','BusyMode','drop','UserData', foregroundDetector);
function [foregroundDetector] = FrameRateDisplay(obj,event,vid,se)
persistent IM;
persistent handlesRaw;
persistent handlesPlot;
trigger(vid);
IM=getdata(vid,1,'uint8');
foregroundDetector = get(obj, 'UserData');
if isempty(handlesRaw)
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, IM);
% if first execution, we create the figure objects
subplot(2,1,1);
handlesRaw=imshow(IM);
title('CurrentImage');
subplot(2,1,2);
handlesPlot=imshow(foreground);
title('Foreground');
else
% We only update what is needed
set(handlesRaw,'CData',IM);
set(obj, 'UserData', foregroundDetector);
end

Answers (1)

Walter Roberson
Walter Roberson on 10 Jun 2015
If handlesRAW is not empty, you fail to step the foreground detector or update the foreground plot.

Categories

Find more on Computer Vision Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!