Search This Blog

Saturday, February 11, 2012

Control Music Using Gesture in MATLAB

I recently develop a coding in matlab for controling music through ur finger motion.
In this program when ever you bring a red colour in front of the webcam then only your song will play otherwise it will stop.
This program is in the developing state and im modying it to be more realistic.

Here is the code in matlab:

%-----------int music file and audio player--------
[y f] = wavread('kh.wav');
p1=audioplayer(y,f);

%---------- int camera ---------------------

hwInfo = imaqhwinfo('winvideo');
device1 = hwInfo.DeviceInfo(1);
device1.SupportedFormats;

vid=videoinput('winvideo',1,'YUY2_320x240');
set(vid,'ReturnedColorSpace','rgb');

triggerconfig(vid,'manual');
    set(vid,'FramesPerTrigger',1);
    set(vid,'TriggerRepeat', 100000);
    start(vid);
    
%-------- taking values -------------

trigger(vid);
image1=getdata(vid,1);
imshow(image1);
for i=1:1500

trigger(vid);
image1=getdata(vid,1);

image1_r=image1(:,:,1);
image1_g=image1(:,:,2);
image1_b=image1(:,:,3);
image1_r1=im2bw(image1_r,140/255);
image1_g1=im2bw(image1_g,130/255);
image1_b1=im2bw(image1_b,130/255);

img=(image1_r1-image1_g1)-image1_b1;
img=img*255;
img=uint8(img);


img=bwareaopen(img,35);
img1=imfill(img,'holes');


[x1 y1]=bwlabel(img1);


if (y1 >0)
      [x y]=find(img1==1);
        mean_x=fix(mean(x));
        mean_y=fix(mean(y));

        if (mean_x > 60 && mean_x < 180 && mean_y > 80 && mean_y < 240)
            play(p1);
       
            string=strcat(num2str(mean_x),'and',num2str(mean_y));

                image2(:,:,1)=double(image1(:,:,1)) .* double(img1);
                image2(:,:,2)=double(image1(:,:,2)) .* double(img1);
                image2(:,:,3)=double(image1(:,:,3)) .* double(img1);

                image2=uint8(image2);

                subplot(1,2,1)
                imshow(image1)
                title('orignal image')

                subplot(1,2,2)
                imshow(image2);
                title(string);

        else
            pause(p1);
             subplot(1,2,1)
                imshow(image1)
                title('no object detected')
                
                subplot(1,2,2)
                imshow(image1)
                title('no object detected')
        end
end
end    
--------------------------------------------------------------------

Change the kh.wav file in wavread command with any wave file present in your computer.. and add that file to the current directory.

Download the m-file from the below link:                  
http://www.mediafire.com/?6xf8ni8xff4ppxb

No comments:

Post a Comment