realtime frame acquisition while recording video

4 次查看(过去 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);

采纳的回答

José-Luis
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.

更多回答(1 个)

Xiaochao
Xiaochao 2013-1-14
Thanks for your answer, but my problem now is where i should put this function. Becasue i write a timer function to record video and save as AVI file.I am not sure how to get frames while recording exactly. I am a new to use matlab to do video and image processing.
  2 个评论
José-Luis
José-Luis 2013-1-14
Please don't place a comment as an answer. It might get confusing for other people joining the conversation.
You could place the snippet I gave you inside the FrameRateDisplay() function and save the red channel, not the entire frame.
Xiaochao
Xiaochao 2013-1-15
How to save the and export the results of the snippet. The results didn't show in workspace.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by