realtime frame acquisition while recording video
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
José-Luis
2013-1-11
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!