This MATLAB code with figure has
following 3 functionalities:
1. Records
a 10 seconds video
2. Play
the recorded video
3. Get
a number of second as input and returns the frame present at that
number of
second in the video
MATLAB Code
function varargout = captureVideo(varargin)
gui_Singleton
= 1;
gui_State
= struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@captureVideo_OpeningFcn, ...
'gui_OutputFcn', @captureVideo_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] =
gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function captureVideo_OpeningFcn(hObject, eventdata,
handles, varargin)
handles.output
= hObject;
guidata(hObject,
handles);
function varargout = captureVideo_OutputFcn(hObject,
eventdata, handles)
varargout{1}
= handles.output;
function Record_Callback(hObject, eventdata, handles)
axes(handles.Preview);
cam=webcam;
aviObj
= avifile('myVideo.avi'); % Create a new AVI file
for i = 1:150 % Capture 150 frames
I=snapshot(cam);
imshow(I);
F = im2frame(I); % Convert I to a movie frame
aviObj = addframe(aviObj,F); %
Add the frame to the AVI file
end
aviObj
= close(aviObj);
clear('cam');
function PlayButton_Callback(hObject, eventdata, handles)
axes(handles.Play);
Video=VideoReader('myVideo.avi');
for i=
1:150
frame=read(Video,i);
imshow(frame);
pause(0.05);
end
function GetFrame_Callback(hObject, eventdata, handles)
axes(handles.Frame);
Video=VideoReader('myVideo.avi');
Show
= {'Enter the second of which You
want the frame'};
Title
= 'Input Second(an integer)';
Lines
= 1;
input
= inputdlg(Show,Title,Lines);
second=str2double(input);
frame_rate=Video.FrameRate;
frame_no=second*frame_rate;
frame=read(Video,frame_no);
imshow(frame);
No comments
Post a Comment