Exporting data while 'live' processing in a GUI
古いコメントを表示
Hi everyone,
The question pertains to the export of data from a GUI that is 'live' processing data from an incoming datastream. The initial question came from some work by Jerome, and is located here on his website ( Link.)
(In order to save time, I have the code from Jerome posted below as well. Please note that this script requires Image Acquisition Toolbox.)
function realVideo()
% Define frame rate
NumberFrameDisplayPerSecond=10;
% Open figure
hFigure=figure(1);
% Set-up webcam video input
try
% For windows
vid = videoinput('winvideo', 1);
catch
try
% For macs.
vid = videoinput('macvideo', 1);
catch
errordlg('No webcam available');
end
end
% Set parameters for video
% Acquire only one frame each time
set(vid,'FramesPerTrigger',1);
% Go on forever until stopped
set(vid,'TriggerRepeat',Inf);
% Get a grayscale image
set(vid,'ReturnedColorSpace','grayscale');
triggerconfig(vid, 'Manual');
% set up timer object
TimerData=timer('TimerFcn', {@FrameRateDisplay,vid},'Period',1/NumberFrameDisplayPerSecond,'ExecutionMode','fixedRate','BusyMode','drop');
% Start video and timer object
start(vid);
start(TimerData);
% We go on until the figure is closed
uiwait(hFigure);
% Clean up everything
stop(TimerData);
delete(TimerData);
stop(vid);
delete(vid);
% clear persistent variables
clear functions;
% This function is called by the timer to display one frame of the figure
function FrameRateDisplay(obj, event,vid)
persistent IM;
persistent handlesRaw;
persistent handlesPlot;
trigger(vid);
IM=getdata(vid,1,'uint8');
if isempty(handlesRaw)
% if first execution, we create the figure objects
subplot(2,1,1);
handlesRaw=imagesc(IM);
title('CurrentImage');
% Plot first value
Values=mean(IM(:));
subplot(2,1,2);
handlesPlot=plot(Values);
title('Average of Frame');
xlabel('Frame number');
ylabel('Average value (au)');
else
% We only update what is needed
set(handlesRaw,'CData',IM);
Value=mean(IM(:));
OldValues=get(handlesPlot,'YData');
set(handlesPlot,'YData',[OldValues Value]);
end
Imagine a case where you are tracking data from a webcam for an 8 hour session. In order to prevent the risk of losing all data in one save session at the end of the day, I would like to break the session into, say, 30 min sessions that I want to save, while still maintaining a display window active.
My initial thought was to save some maintain some type of a counter, where upon reaching 30 minutes, it would output a file (i.e. 'YData', [OldValues Value].) However, I am not sure if the write time can potentially have an impact on the data analysis/updating screen. Is this something that can be introduced in as a separate timerFcn?
I'm guessing that it's not the first time this question has been asked, so any direction/thoughts would be most appreciated.
Thanks.
採用された回答
その他の回答 (1 件)
カテゴリ
ヘルプ センター および File Exchange で National Instruments Frame Grabbers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!