Filter löschen
Filter löschen

realtime frame acquisition while recording video

4 Ansichten (letzte 30 Tage)
Xiaochao
Xiaochao am 11 Jan. 2013
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);

Akzeptierte Antwort

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

Weitere Antworten (1)

Xiaochao
Xiaochao am 14 Jan. 2013
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 Kommentare
José-Luis
José-Luis am 14 Jan. 2013
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 am 15 Jan. 2013
How to save the and export the results of the snippet. The results didn't show in workspace.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by