the code is giving different finger count.

14 views (last 30 days)
I am working on a hand gesture recognition system. The code attached below gives variable finger count. Can someone please help me fix the issue or help me with a working code of hand gesture recognition for v2017b? Some functions are used from Virtual synchronous Machine.
%%clear stored variables, command windows, close any open windows
clear;
clc;
close all;
%%sets videoinput to the webcam, and the webcam device 1
vid=videoinput('winvideo', 1, 'YUY2_640x480');
set(vid,'ReturnedColorspace','grayscale')
%%pause 2 seconds before snapshot of background image
pause(2);
IM1=getsnapshot(vid); %get snapshot from the webcam video and store to IM1 variable
figure(1);subplot(3,2,1);imshow(IM1);title('Background'); %open up a figure and show the image stored in IM1 variable
pause(2);
IM2=getsnapshot(vid); %get snapshot of test image and store to
variable IM2
figure(1);subplot(3,2,2);imshow(IM2);title('Gesture'); %open up a figure and show the image stored in IM2 variable
IM3 = IM1 - IM2; %subtract Backround from Image
figure(1);subplot(3,2,3);imshow(IM3);title('Subtracted'); %show the subtracted image
lvl = graythresh(IM3); %find the threshold value using Otsu's method for black and white
IM3 = im2bw(IM3, lvl); %Converts image to BW, pixels with value higher than threshold value is changed to 1, lower changed to 0
figure(1);subplot(3,2,4);imshow(IM3);title('Black&White');
imwrite(IM3,'gray.jpeg');
%%data driven threshold based on the max/min of the image histogram
hi_grey=vsg('HighestGrey',IM3);
disp('highestgrey done');
lo_grey=vsg('LowestGrey',IM3);
disp('lowestgrey done');
thresh=uint8(3*(hi_grey+lo_grey)/4);
%%display the resulting image
IM4=vsg('LowPass',IM3);
disp('lowpass done');
%%apply the threshold to the image and display the resultant binary image
IM5=vsg('Threshold',IM4,thresh);
disp('threshold done');
IM5=uint8(IM5);
figure(1);subplot(3,2,5);imshow(IM5);
%%invert Image
[IM6]=vsg('Inverse',IM5);
figure(1);subplot(3,2,6);imshow(IM6);
title ('Inverted Binary Image');
%%mask boundary pixels to avoid any edge effects
IM7=vsg('MaskImg',IM6,20);
figure(2);subplot(3,2,1);imshow(IM7);
image(uint8(IM7));
%%Get width
[num1]=vsg('GetWidth',IM3);
[num2]=num1*.5;
%%Thin
[IM8]=vsg('ThinImg',IM7,70);
%%Join lines
[IM9]=vsg('LINFilter',IM8);
figure(2);subplot(3,2,2);imshow(IM9);
image(uint8(IM9));
%%Apply centroid and find position
[IM10]=vsg('Centroid',IM9);
[p1]=vsg('FWP',IM10);
%%Fill Circle
[IM11]=vsg('FillCircle',IM9,p1,num2,[0,0,0]);
%%Fill box
[IM12]=vsg('FillBox',IM11,[0,1200],[1400,1400],[0,0,0]);
figure(2);subplot(3,2,3);imshow(IM11);
image(uint8(IM12));
%%Count the number of blobs and display finger count
[num3]= vsg('CountBlobs',IM12);
figure(2);subplot(3,2,4);imshow(IM12);
image(uint8(IM2));
text(50,50,strcat('\color{red}Finger count:',num2str(num3)))

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!