% Everything starting with % sign is a comment
% i) First of all set the current directory of matlab to C: , if you don't know how to , then skip this step
% ii) Copy your video to c: drive
% iii) now replace the video with exact video name , the video should be avi and should be of less resolution for effective processing.
% code starts below
video=mmreader('video.avi'); % read the video
nframes= video.numberofframes; % total number of frames in the video
cd c:\\ % sets the current directory to C: , if you even didn't set , it will set it to C:
for i=1:nframes
image = read(video ,i); % to access each frame
imshow(image); % to show each frame
end % end of for loop
Human Detection and Tracking in Matlab , Complete references and code with step by step guide
Thursday, March 3, 2011
Monday, February 28, 2011
Motion Detection
function varargout = prog(varargin)
% PROG M-file for prog.fig
% PROG, by itself, creates a new PROG or raises the existing
% singleton*.
%
% H = PROG returns the handle to a new PROG or the handle to
% the existing singleton*.
%
% PROG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PROG.M with the given input arguments.
%
% PROG('Property','Value',...) creates a new PROG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before prog_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to prog_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help prog
% Last Modified by GUIDE v2.5 28-Feb-2011 01:24:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @prog_OpeningFcn, ...
'gui_OutputFcn', @prog_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 prog is made visible.
function prog_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to prog (see VARARGIN)
% Choose default command line output for prog
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes prog wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = prog_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
clear
cd c:\\
video=mmreader('video.avi');
disp(video.width);
bg= read(video,1);
nframes= video.numberofframes;
for i=1:nframes-1
image1 = read(video ,i);
image2 = read(video ,i+1);
image1 = rgb2gray(image1);
image2 = rgb2gray(image2);
motion=image2-image1;
width=0;
height=0;
left=0;
right=0;
top=0;
bottom=0;
for m=1:video.height
for n=1:video.width
if(motion(m,n)>=50)
%motion(m,n)=255;
if(top==0)
top=m;
end
if(n>right)
right=n;
end
if(left==0)
left=n;
end
if(n left=n;
end
if(bottom==0)
bottom=m;
end
if(m>bottom)
bottom=m;
end
end
end
end
for l=1:video.height
for j=1:video.width
if(lbottom)
motion(l,j)=0;
end
if(jright)
motion(l,j)=0;
end
end
end
width=right-left;
height=bottom-top;
imshow(motion);
rectangle('position',[left-3,top-3,width+6,height+6],'EdgeColor','b');
%rectangle('position',[left-1,top-1,width+2,height+2],'EdgeColor','k');
drawnow;
end
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on key press with focus on pushbutton1 and none of its controls.
function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
clear
cd c:\\
video=mmreader('video.avi');
for u=1:3:video.numberofframes
imshow(read(video,u));
drawnow
end
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
clear
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% PROG M-file for prog.fig
% PROG, by itself, creates a new PROG or raises the existing
% singleton*.
%
% H = PROG returns the handle to a new PROG or the handle to
% the existing singleton*.
%
% PROG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PROG.M with the given input arguments.
%
% PROG('Property','Value',...) creates a new PROG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before prog_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to prog_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help prog
% Last Modified by GUIDE v2.5 28-Feb-2011 01:24:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @prog_OpeningFcn, ...
'gui_OutputFcn', @prog_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 prog is made visible.
function prog_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to prog (see VARARGIN)
% Choose default command line output for prog
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes prog wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = prog_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
clear
cd c:\\
video=mmreader('video.avi');
disp(video.width);
bg= read(video,1);
nframes= video.numberofframes;
for i=1:nframes-1
image1 = read(video ,i);
image2 = read(video ,i+1);
image1 = rgb2gray(image1);
image2 = rgb2gray(image2);
motion=image2-image1;
width=0;
height=0;
left=0;
right=0;
top=0;
bottom=0;
for m=1:video.height
for n=1:video.width
if(motion(m,n)>=50)
%motion(m,n)=255;
if(top==0)
top=m;
end
if(n>right)
right=n;
end
if(left==0)
left=n;
end
if(n
end
if(bottom==0)
bottom=m;
end
if(m>bottom)
bottom=m;
end
end
end
end
for l=1:video.height
for j=1:video.width
if(l
motion(l,j)=0;
end
if(j
motion(l,j)=0;
end
end
end
width=right-left;
height=bottom-top;
imshow(motion);
rectangle('position',[left-3,top-3,width+6,height+6],'EdgeColor','b');
%rectangle('position',[left-1,top-1,width+2,height+2],'EdgeColor','k');
drawnow;
end
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on key press with focus on pushbutton1 and none of its controls.
function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
clear
cd c:\\
video=mmreader('video.avi');
for u=1:3:video.numberofframes
imshow(read(video,u));
drawnow
end
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
clear
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Subscribe to:
Comments (Atom)