MATLAB Examples

Contents

function varargout = untitled(varargin)
% Last Modified by GUIDE v2.5 09-Apr-2014 00:51:57
% Gregory Kalliatakis
%Dep. of Informatics Engineering,
%Heraklion,Crete

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_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
% End initialization code - DO NOT EDIT


% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

% Update handles structure
guidata(hObject, handles);




% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;



function fps_Callback(hObject, eventdata, handles)



% --- Executes during object creation, after setting all properties.
function fps_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function trigger_Callback(hObject, eventdata, handles)



% --- Executes during object creation, after setting all properties.
function trigger_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function vdfilename_Callback(hObject, eventdata, handles)
% get(hObject,'String') returns contents of vdfilename as text
handles.vdFileName=get(hObject,'String');
handles.vdFileName1=char(handles.vdFileName);
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function vdfilename_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

Initialize and start video recording for .avi output

All the parameters for the recording are set while the corresponding folder is created for storing the output.Then the recording process starts ! --- Executes on button press in vdrecord.

function vdrecord_Callback(hObject, eventdata, handles)
tic;
fps= str2double(get(handles.fps,'String')); %gets the frames per second given by the user
project_dir=get(handles.project_name,'String'); %gets the main folder name given by the user
name_of_video=get(handles.vdfilename,'String');
vid = videoinput('winvideo', 1,'YUY2_640x480');
setappdata(handles.vdrecord,'vid',vid);
mkdir(project_dir) % create folder with the given name by the user
filename_string=strcat(project_dir,'\',name_of_video,'.avi'); % create filename string
aviobj = VideoWriter(filename_string);  % Create a |VideoWriter| object.
 vid.DiskLogger = aviobj;
aviobj.Quality = 50;
aviobj.FrameRate = fps;
 vid.LoggingMode = 'disk';
 vid.TriggerRepeat = Inf;
 vid.FramesPerTrigger = Inf;
% preview(vid);
start(vid);
wait(vid,10000,'Logging')
vid.Running;
vid.Logging;
vid.DiskLoggerFrameCount;
   while (vid.DiskLoggerFrameCount ~= vid.FramesAcquired)
   pause(1);
   end
   vid.DiskLoggerFrameCount;
   close(aviobj);
   delete(vid);
   elaspsed_time=toc;
   disp(elaspsed_time);

Stops the recording and save .avi output

--- Executes on button press in vdstop.

function vdstop_Callback(hObject, eventdata, handles)
video= getappdata(handles.vdrecord,'vid');
stop(video);

guidata(hObject,handles);

function project_name_Callback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function project_name_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

Closes the application window

--- Executes on button press in quit.

function quit_Callback(hObject, eventdata, handles)
close all
close
return

Initialize and start video recording for .mat output

All the parameters for the recording are set while the corresponding folder is created for storing the output.Then the recording process starts ! --- Executes on button press in vdrecrod2.

function vdrecrod2_Callback(hObject, eventdata, handles)
tic;
fps= str2double(get(handles.fps,'String')); %gets the frames per second given by the user
project_dir=get(handles.project_name,'String');
name_of_video=get(handles.vdfilename,'String');
vid = videoinput('winvideo', 1,'YUY2_640x480');
setappdata(handles.vdrecrod2,'vid2',vid);
mkdir(project_dir) %  create folder with the given name by the user
filename_string=strcat(project_dir,'\',name_of_video); % create filename string
setappdata(handles.vdrecrod2,'filename_string',filename_string);
 vid.LoggingMode = 'memory';
 vid.TriggerRepeat = Inf;
 vid.FramesPerTrigger = Inf;
 %preview(vid);
 start(vid);
 elaspsed_time=toc;
 disp(elaspsed_time);

Stops the recording and save .mat output

--- Executes on button press in vdstop2.

function vdstop2_Callback(hObject, eventdata, handles)
video2= getappdata(handles.vdrecrod2,'vid2');
stop(video2);
video_data=getdata(video2);
filename_string=getappdata(handles.vdrecrod2,'filename_string');
filename_string=strcat(filename_string,'.mat');
save(filename_string, 'video_data');
delete(video2);
guidata(hObject,handles);