Üye
[CODE title="Gesture Control"]function varargout = Gesture_Control(varargin)
% GESTURE_CONTROL MATLAB code for Gesture_Control.fig
% GESTURE_CONTROL, by itself, creates a new GESTURE_CONTROL or raises the existing
% singleton*.
%
% H = GESTURE_CONTROL returns the handle to a new GESTURE_CONTROL or the handle to
% the existing singleton*.
%
% GESTURE_CONTROL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GESTURE_CONTROL.M with the given input arguments.
%
% GESTURE_CONTROL('Property','Value',...) creates a new GESTURE_CONTROL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gesture_Control_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gesture_Control_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 Gesture_Control
% Last Modified by GUIDE v2.5 03-Feb-2018 13:01:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gesture_Control_OpeningFcn, ...
'gui_OutputFcn', @Gesture_Control_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 Gesture_Control is made visible.
function Gesture_Control_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 Gesture_Control (see VARARGIN)
% Choose default command line output for Gesture_Control
handles.output = hObject;
imaqreset
delete(instrfind)
set(handles.axes1,'XColor',[1,1,1]);
set(handles.axes1,'YColor',[1,1,1]);
set(handles.axes1,'XTickLabel','');
set(handles.axes1,'YTickLabel','');
set(handles.axes2,'XColor',[1,1,1]);
set(handles.axes2,'YColor',[1,1,1]);
set(handles.axes2,'XTickLabel','');
set(handles.axes2,'YTickLabel','');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gesture_Control wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gesture_Control_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 Start_Camera_btn.
function Start_Camera_btn_Callback(hObject, eventdata, handles)
% hObject handle to Start_Camera_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imaqreset
vid = videoinput('winvideo', 1, 'MJPG_640x480');
src = getselectedsource(vid);
vid.FramesPerTrigger = Inf;
start(vid);
axes(handles.axes1);
h1 = image(zeros(480,640)); % create image object
axis ij; % flip the image
preview(vid,h1)
handles.vid = vid;
guidata(hObject,handles);
% --- Executes on button press in Recognise_btn.
function Recognise_btn_Callback(hObject, eventdata, handles)
% hObject handle to Recognise_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
delete(instrfind) % close previously opened serial ports
load Gesture_features data group
vid = handles.vid;
I = getsnapshot(vid);
im = imresize(I,[200,NaN]);
% imshow(im,'Parent',handles.axes1);
% drawnow
gr = rgb2gray(im);
L=graythresh(gr);
BW1=im2bw(gr,L);
BW1=bwareaopen(BW1,500);
BB=regionprops(BW1,'Boundingbox');
object = imcrop(gr,BB(1).BoundingBox);
object = imresize(object,[100,50]);
imshow(object,'Parent',handles.axes2);
drawnow
[testfeat] = hog_feature_vector(object);
% class = knnclassify(testfeat,data,group);
Mdl = fitcknn(data,group);
class = predict(Mdl,testfeat);
%% Serial Port setup and connection
% Serial_port = serial('COM6', 'BaudRate', 9600);
% fopen(Serial_port);
switch class
case 1
tts('Light is On');
% fprintf(Serial_port,'a'); fclose(Serial_port);
case 2
tts('Fan is on');
% fprintf(Serial_port,'b'); fclose(Serial_port);
case 3
tts('TV is on');
% fprintf(Serial_port,'c'); fclose(Serial_port);
case 4
tts('Music system is on');
% fprintf(Serial_port,'d'); fclose(Serial_port);
end
% --- Executes on button press in Exit_btn.
function Exit_btn_Callback(hObject, eventdata, handles)
% hObject handle to Exit_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(instrfind)
imaqreset
close all;
% --- Executes on button press in Training.
function Training_Callback(hObject, eventdata, handles)
% hObject handle to Training (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=[];
group=[];
addr = genpath('.');
addpath(addr);
set(handles.text1, 'String', 'Training the Database !');
dos('attrib -h -r -s /S .\dataset\Thumbs.db');
dos('del /S .\dataset\Thumbs.db');
folder=dir('.\dataset');
count=0;
%%
for mn=3:length(folder)
count=count+1;
address=strcat('.\dataset\',folder(mn).name);
files=dir(address);
num=numel(files);
for i=3:num
msg = sprintf('Procecssing Folder %s, File: %d, Filename -> %s\n',folder(mn).name,i-2,files(i).name);
fprintf(msg);
str=strcat('.\dataset\',folder(mn).name,'\',files(i).name);
im=imread(str);
im = imresize(im,[200,NaN]);
imshow(im,'Parent',handles.axes1);
drawnow
gr = rgb2gray(im);
L=graythresh(gr);
BW1=im2bw(gr,L);
BW1=bwareaopen(BW1,500);
BB=regionprops(BW1,'Boundingbox');
object = imcrop(gr,BB(1).BoundingBox);
object = imresize(object,[100,50]);
imshow(object,'Parent',handles.axes2);
drawnow
[feat] = hog_feature_vector(object);
group = [group ; count];
data=[data ; feat];
end
end
save Gesture_features data group[/CODE]
% GESTURE_CONTROL MATLAB code for Gesture_Control.fig
% GESTURE_CONTROL, by itself, creates a new GESTURE_CONTROL or raises the existing
% singleton*.
%
% H = GESTURE_CONTROL returns the handle to a new GESTURE_CONTROL or the handle to
% the existing singleton*.
%
% GESTURE_CONTROL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GESTURE_CONTROL.M with the given input arguments.
%
% GESTURE_CONTROL('Property','Value',...) creates a new GESTURE_CONTROL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gesture_Control_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gesture_Control_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 Gesture_Control
% Last Modified by GUIDE v2.5 03-Feb-2018 13:01:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gesture_Control_OpeningFcn, ...
'gui_OutputFcn', @Gesture_Control_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 Gesture_Control is made visible.
function Gesture_Control_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 Gesture_Control (see VARARGIN)
% Choose default command line output for Gesture_Control
handles.output = hObject;
imaqreset
delete(instrfind)
set(handles.axes1,'XColor',[1,1,1]);
set(handles.axes1,'YColor',[1,1,1]);
set(handles.axes1,'XTickLabel','');
set(handles.axes1,'YTickLabel','');
set(handles.axes2,'XColor',[1,1,1]);
set(handles.axes2,'YColor',[1,1,1]);
set(handles.axes2,'XTickLabel','');
set(handles.axes2,'YTickLabel','');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Gesture_Control wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gesture_Control_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 Start_Camera_btn.
function Start_Camera_btn_Callback(hObject, eventdata, handles)
% hObject handle to Start_Camera_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imaqreset
vid = videoinput('winvideo', 1, 'MJPG_640x480');
src = getselectedsource(vid);
vid.FramesPerTrigger = Inf;
start(vid);
axes(handles.axes1);
h1 = image(zeros(480,640)); % create image object
axis ij; % flip the image
preview(vid,h1)
handles.vid = vid;
guidata(hObject,handles);
% --- Executes on button press in Recognise_btn.
function Recognise_btn_Callback(hObject, eventdata, handles)
% hObject handle to Recognise_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
delete(instrfind) % close previously opened serial ports
load Gesture_features data group
vid = handles.vid;
I = getsnapshot(vid);
im = imresize(I,[200,NaN]);
% imshow(im,'Parent',handles.axes1);
% drawnow
gr = rgb2gray(im);
L=graythresh(gr);
BW1=im2bw(gr,L);
BW1=bwareaopen(BW1,500);
BB=regionprops(BW1,'Boundingbox');
object = imcrop(gr,BB(1).BoundingBox);
object = imresize(object,[100,50]);
imshow(object,'Parent',handles.axes2);
drawnow
[testfeat] = hog_feature_vector(object);
% class = knnclassify(testfeat,data,group);
Mdl = fitcknn(data,group);
class = predict(Mdl,testfeat);
%% Serial Port setup and connection
% Serial_port = serial('COM6', 'BaudRate', 9600);
% fopen(Serial_port);
switch class
case 1
tts('Light is On');
% fprintf(Serial_port,'a'); fclose(Serial_port);
case 2
tts('Fan is on');
% fprintf(Serial_port,'b'); fclose(Serial_port);
case 3
tts('TV is on');
% fprintf(Serial_port,'c'); fclose(Serial_port);
case 4
tts('Music system is on');
% fprintf(Serial_port,'d'); fclose(Serial_port);
end
% --- Executes on button press in Exit_btn.
function Exit_btn_Callback(hObject, eventdata, handles)
% hObject handle to Exit_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(instrfind)
imaqreset
close all;
% --- Executes on button press in Training.
function Training_Callback(hObject, eventdata, handles)
% hObject handle to Training (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=[];
group=[];
addr = genpath('.');
addpath(addr);
set(handles.text1, 'String', 'Training the Database !');
dos('attrib -h -r -s /S .\dataset\Thumbs.db');
dos('del /S .\dataset\Thumbs.db');
folder=dir('.\dataset');
count=0;
%%
for mn=3:length(folder)
count=count+1;
address=strcat('.\dataset\',folder(mn).name);
files=dir(address);
num=numel(files);
for i=3:num
msg = sprintf('Procecssing Folder %s, File: %d, Filename -> %s\n',folder(mn).name,i-2,files(i).name);
fprintf(msg);
str=strcat('.\dataset\',folder(mn).name,'\',files(i).name);
im=imread(str);
im = imresize(im,[200,NaN]);
imshow(im,'Parent',handles.axes1);
drawnow
gr = rgb2gray(im);
L=graythresh(gr);
BW1=im2bw(gr,L);
BW1=bwareaopen(BW1,500);
BB=regionprops(BW1,'Boundingbox');
object = imcrop(gr,BB(1).BoundingBox);
object = imresize(object,[100,50]);
imshow(object,'Parent',handles.axes2);
drawnow
[feat] = hog_feature_vector(object);
group = [group ; count];
data=[data ; feat];
end
end
save Gesture_features data group[/CODE]
Moderatörün son düzenlenenleri: