Sunday 11 August 2013

Music Player with Hand Gesture Control using Neural Network

Hello guys, I have already posted an article on hand gesture recognition using neural network,if you have not see it then please go through it first.Well,here is the Link 

So,using the previous implementation I am now going to show you how you can built a Music Player that will be controlled by hand gestures.That means there will be a separate predefined gesture for performing every individual task that will be performed on the player.

That means there will be an unique gesture for Play,another for pause and so on.


So here are the steps using which you can built it easily :

1. I hope you are all familiar with Matlab GUI,if not then please see this Link 

2. Now here I am not going to briefly explain how to play and pause music in matlab,here my main focus is to tell you how can you control this using hand gestures.

Still,if any one has any problem in building the music player he or she can tell his or her problem through comment,then I will post the code for that later.

3. For example lets assume we use the following gesture for play action.





Then we have to get at least 5-10 pic like this and save it into a folder.

4.  Now train the network with the sample picture,so that when ever any similar gesture is detected during testing,then system would perform some task.

For code reference,please visit this link below :

Gesture Recognition using Neural Network

5.Now the point is where to insert the code. Well for every recognition system we go for a threshold value to determine whether it is the desired result.In the previous Hand gesture recognition system post also I have done the same in the end.

So insert the desired music player action code within that MATCH_FOUND code block.
like this,

if(PLAY_IMG_MATCH_FOUND==TRUE)
{
  //Music player play code
}

Similarly if you want to perform any hard ware related task then just go to this link  and insert the code in the same block as I mentioned before.

Just for example,I have shown this one example PLAY action with this sample images and one gesture.

You can use different gestures for performing different task like PAUSE,STOP etc.

There are lot more things to do with this project...try it yourself, and please let me know about your new works...best of luck...thanks for visiting,have lots of fun :)

Sunday 4 August 2013

Gesture Recognition using Neural Network in MATLAB Code Part 3

preprocess_gesture.m 

If you have not seen previous post then please go through it first then come back   go to Previous Part


Create a Menu

clc
F = MENU('Choose a database set','Test Set','Train Set'); 
if F==1
K = MENU('Choose a file','Test O');

FOR TESTING A DATASET

if K == 1
    loop=5 
    for i=1:loop 
       string = ['test\O\' num2str(i) '.tif']; 
       Rimages{i} = imread(string); 
    end 

 end 
 end 
end;

FOR TRAINING


if F==2 
    loop=3    %Set loop to 3. All train sets have 3 images 
    L = MENU('Choose a file','Train O'); 
if L == 1 

    for i=1:loop 
    string = ['train\O\' num2str(i) '.tif']; 
    Rimages{i} = imread(string); 
    end
end 
end 

Now do what I am doing here


T{i}=imresize(Timages{i},[150,140]); 

    x = [0 -1 1];                               
    y = [0 1 -1]';

dx{i} = convn(T{i},x,'same');
dy{i} = convn(T{i},y,'same');
gradient{i} = dy{i} ./dx{i};
theta{i} = atan(gradient{i});
cl{i}= im2col(theta{i},[1 1],'distinct');
 N{i} = (cl{i}*180)/3.14159265359; .
c1{i}=(N{i}>0)&(N{i}<10 div="" nbsp="">
    s1{i}=sum(c1{i}); 

    c2{i}=(N{i}>10.0001)&(N{i}<20 div="" nbsp="">
    s2{i}=sum(c2{i}); 

    c3{i}=(N{i}>20.0001)&(N{i}<30 div="" nbsp="">
    sum(c3{i}); 
    s3{i}=sum(c3{i}); 

    c4{i}=(N{i}>30.0001)&(N{i}<40 div="" nbsp="">
    sum(c4{i}); 
    s4{i}=sum(c4{i}); 

    c5{i}=(N{i}>40.0001)&(N{i}<50 div="" nbsp="">
    sum(c5{i}); 
    s5{i}=sum(c5{i}); 

    c6{i}=(N{i}>50.0001)&(N{i}<60 div="" nbsp="">
    sum(c6{i}); 
    s6{i}=sum(c6{i}); 

    c7{i}=(N{i}>60.0001)&(N{i}<70 div="" nbsp="">
    sum(c7{i}); 
    s7{i}=sum(c7{i}); 

    c8{i}=(N{i}>70.0001)&(N{i}<80 div="" nbsp="">
    sum(c8{i}); 
    s8{i}=sum(c8{i}); 

    c9{i}=(N{i}>80.0001)&(N{i}<90 div="" nbsp="">
    sum(c9{i}); 
    s9{i}=sum(c9{i}); 

    c10{i}=(N{i}>90.0001)&(N{i}<100 div="" nbsp="">
    sum(c10{i}); 
    s10{i}=sum(c10{i}); 

    c11{i}=(N{i}>-89.9)&(N{i}<-80 div="" nbsp="">
    sum(c11{i}); 
    s11{i}=sum(c11{i}); 
    c12{i}=(N{i}>-80.0001)&(N{i}<-70 div="" nbsp="">
    sum(c12{i}); 
    s12{i}=sum(c12{i}); 

    c13{i}=(N{i}>-70.0001)&(N{i}<-60 div="" nbsp="">
    sum(c13{i}); 
    s13{i}=sum(c13{i}); 

    c14{i}=(N{i}>-60.0001)&(N{i}<-50 div="" nbsp="">
    sum(c14{i}); 
    s14{i}=sum(c14{i}); 

    c15{i}=(N{i}>-50.0001)&(N{i}<-40 div="" nbsp="">
    sum(c15{i}); 
    s15{i}=sum(c15{i}); 

    c16{i}=(N{i}>-40.0001)&(N{i}<-30 div="" nbsp="">
    sum(c16{i}); 
    s16{i}=sum(c16{i}); 

    c17{i}=(N{i}>-30.0001)&(N{i}<-20 div="" nbsp="">
    sum(c17{i}); 
    s17{i}=sum(c17{i}); 

    c18{i}=(N{i}>-20.0001)&(N{i}<-10 div="" nbsp="">
    sum(c18{i}); 
    s18{i}=sum(c18{i}); 

    c19{i}=(N{i}>-10.0001)&(N{i}<-0 .0001="" div="" nbsp="">
    sum(c19{i}); 
    s19{i}=sum(c19{i}); 

    D{i}= [s1{i} s2{i} s3{i} s4{i} s5{i} s6{i} s7{i} s8{i} s9{i} s10{i} s11{i} s12{i} s13{i} s14{i} s15{i} s16{i} s17{i} s18{i} s19{i}]; 

close(w);

Guys thanks for visiting my blog,Have fun :)


This is the end of gesture recognition


Please LIKE and COMMENT...


Gesture Recognition using Neural Network in MATLAB Code Part 2

neuralnetwork_gesture.m

Go to First Part                             Go to Next Part



echo on
clc
pause
clc

Store the training informations in a test file

fid = fopen('train.txt','rt');
P1 = fscanf(fid,'%f',[19,inf]);
P=P1;

Open some text file using code to write and fetch the required information about image.


fid = fopen('testO.txt','rt');
TS1 = fscanf(fid,'%f',[19,inf]);

%(As here we are only testing alphabet 'O')

fid = fopen('target8.txt','rt');
T = fscanf(fid,'%f',[8,inf]);

It has been found that the optimal number of neurons for  the hidden layer is 85

S1 = 85;
S2 = 5;

Now we have to initialize pre-processing layer

[W1,b1] = initp(P,S1);

We also have to initialize learning layer

 [W2,b2] = initp(S1,T);

pause 

NOW TRAIN THE NETWORK


A1 = simup(P,W1,b1);
TP = [1 500]; 
pause
clf reset
figure(gcf)

% resize the frame size
setfsize(600,300);

[W2,b2,epochs,errors] = trainp(W2,b2,A1,T,TP);

pause
clc 

ploterr(errors); 


pause

M = MENU('Choose a file resolution','Test O');    %as we are only showing 'O',you can add more
if M == 1 
 TS = TS1;
else 
 disp('Wrong input');

a1 = simup(TS,W1,b1);        

a2 = simup(a1,W2,b2)      

echo off 

Next part will be posted in next Post,Thanks for visiting have fun

Gesture Recognition using Neural Network in MATLAB 


Gesture Recognition using Neural Network in MATLAB Code

Hi guys,many people were requesting for gesture recognition code so here it is ...
Well for any recognition system there are some simple common states what we also followed here they are:


1. First you have to have data set.Which you have to prepare or download from any website according to your demand.Like you want to want to recognize an alphabet 'O'.Then you have to provide particular data set for 'O'.


Like this :



Okey this is only one picture but I recommend at least 5 pictures you have to give to recognize a gesture.


2. Now give matlab access to the data sets providing particular path of the folder on your system,it is better to make different folder for different alphabet sample.


3. Now you have to train the network.I will show you how to do it in later part.It is the most important part,here you are making your network understand that " ANY IMAGE LIKE-THIS IS ALPHABET 'O' "


4.Here you need to provide an algorithm that will set such a threshold value that will decide whether the test image is 'O' or NOT.


5.Now you need some more sample of 'O' to test the network whether it is coming fine.


6.Well that is it. I will give you the sample code in my next post so that it will be easy for you to implement.


Proceed to Next Part


Thanks a lot for visiting have fun.