realtime frame acquisition while recording video
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wrote a program of video recording and saving and I want add some codes into it to achieve realtime frame acquisition and getting r of rgb of the frames. My code is shown below:
function realtime_test()
global movie name vid;
% Define frame rate
NumberFrameDisplayPerSecond=10;
% Open figure
hFigure=figure(1);
% Set-up webcam video input
vid = videoinput('winvideo', 1);
% 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','rgb')
vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
hImage = imshow( zeros(vidRes(2), vidRes(1), nBands));
preview(vid,hImage);
triggerconfig(vid, 'Manual');
% set up timer object
TimerData=timer('TimerFcn', {@FrameRateDisplay,vid},'Period',1/NumberFrameDisplayPerSecond,'ExecutionMode','fixedRate','BusyMode','drop');
name = 'Realtime';
movie=avifile(name,'compression','none');
% 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);
movie=close(movie);
% clear persistent variables
clear functions;
% This function is called by the timer to display one frame of the figure
function FrameRateDisplay(obj, event,vid)
global movie frame;
frame=uint8(getsnapshot(vid));
movie=addframe(movie,frame);
0 Kommentare
Akzeptierte Antwort
José-Luis
am 11 Jan. 2013
If your frame is really rgb data, then the red channel will be:
your_red = squeeze(frame(:,:,1));
In the future please try posting a minimum working example.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!