I want to build up hand gestures detection and recognition algorithm, I need help with my code and sadly it doesn't work

4 views (last 30 days)
Ahmed El Sheikh
Ahmed El Sheikh on 10 Jul 2016
Commented: Image Analyst on 12 Jul 2016
%vid to intialize a variable to save incoming video %videoinput to get video from webcam, video format, adopter number
vid = videoinput('winvideo', 1);
%Frames per trigger specifies the number of frames acquired, inf used %to state that frames will be acquired till an error occurs or stopped
set(vid,'FramesPerTrigger',inf);
%Returned color space is rgb as we are using this format
set(vid,'ReturnedColorSpace','rgb')
%extract images every 5 milli-second
vid.FrameGrabInterval=5;
%start acquiring video
start(vid);
while(vid.FramesAvailable <= 20)
% Get a snapshot of the current frame
data = getsnapshot(vid);
%Skin Color Extraction
J=rgb2ycbcr(data);
L=graythresh(J(:,:,2));
BW=im2bw(J(:,:,2),L);
BW1=~BW;
M=graythresh(J(:,:,3));
BW2=im2bw(J(:,:,3),M);
o=BW1.*BW2;
roi=o;
% Here we do the image blob analysis.
% We get a set of properties for each labeled region.
stats = regionprops(roi, 'BoundingBox', 'Centroid');
imshow(data);
hold on
%This is a loop to bound the skin colour in a rectangular box.
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','y','LineWidth',1)
plot(bc(1),bc(2), '-m+')
end
hold off
end
stop(vid); flushdata(vid);

Answers (1)

Image Analyst
Image Analyst on 10 Jul 2016
It looks like your skin detection is all messed up. Whoever told you to use graythresh() for finding skin tone colored blobs in your image is mistaken. You need to customize your threshold to use fairly fixed thresholds. graythresh() tries to automatically find a threshold based on what's there and it can get confused if there is not enough skin tone, or too much, or the presence of other colors. Try the Color Thresholder app on the Apps tab of the tool ribbon to home in on the threshold you should use.
  10 Comments
Image Analyst
Image Analyst on 12 Jul 2016
Why? Do you have flesh colored hands in front of a flesh colored background screen? I'd hope not. Why not attach an image so we can see it? Edge detection is rarely the best solution - I don't know why everyone wants to try it as a first step. I'm pretty sure you're best off looking at the colors of the hand and surrounding scene rather than doing edge detection, because, after all, things like faces and clothing will also have lots of edges in them so how will you tell the difference between hand edges and clothing edges? Maybe if only the hands are moving you can use optical flow, or combine optical flow with color segmentation.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!