Exporting data while 'live' processing in a GUI
10 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Adam Hug
on 30 Jun 2015
Before investing a lot of effort into coding this up, try running a simple experiment where you save one frame every 1/60 of a second (or whatever your video camera's sampling rate is) and then output it to your screen. If this cannot be done in real time, then you will need to inevitably drop frames or reduce the image quality in your final save. This kind of setup is very hardware dependent so it is a good idea to know your limitations going in.
0 Comments
More Answers (1)
See Also
Categories
Find more on National Instruments Frame Grabbers 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!