Detection problem in a video for hand detection?
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm doing hand detection and tracking using skin color method. I'm not using Viola-Jones method as it requires training. The problem is that when i use the detection code(shown below) the hand is detected but when i use the same code in a video nothing is detected.
The code for the detection of hand is;
%Read the image, and capture the dimensions
tic;
img_orig = imread('65.png');
height = size(img_orig,1);
width = size(img_orig,2);
%Initialize the output images
out = img_orig;
bin = zeros(height,width);
%Convert the image from RGB to YCbCr
img_ycbcr = rgb2ycbcr(img_orig);
Cb = img_ycbcr(:,:,2);
Cr = img_ycbcr(:,:,3);
%Detect Skin
[r,c,v] = find(Cb>=67 & Cb<=137 & Cr>=133 & Cr<=173);
numind = size(r,1);
numcol = size(r,2);
%Mark Skin Pixels
for i=1:numind
out(r(i),c(i),:) = [0 0 255];
bin(r(i),c(i)) = 1;
end
% Detect radius
[x1,y1] = find(out(:,:,3) == 255, 1,'first');
[x2,y2] = find(out(:,:,3) == 255, 1, 'last');
% Detect Hand Center
hits = 0;
hitsArr = zeros(1,height);
for i = 1:height
hits = numel(find(bin(i,:) == 1));
hitsArr(i) = hits;
end
maxHitr = max(hitsArr);
y = find(hitsArr == maxHitr,1,'first');
hitsArr = zeros(1,width);
for i = 1:width
hits = numel(find(bin(:,i) == 1));
hitsArr(i) = hits;
end
maxHitc = max(hitsArr);
x = find(hitsArr == maxHitc,1,'first');
label = 'Hand';
position = [x y abs(y2-y1)/2; x y 1];
img_out = insertObjectAnnotation(img_orig,'Circle',position,label);
imshow(img_orig);
figure; imshow(img_out);title('Detected hand');
imwrite(img_out,'hand_detect.jpg');
% viscircles([x y],abs(y2-y1)/2,'EdgeColor','r');
% viscircles([x y],1,'EdgeColor','r');
% figure; imshow(out);
figure; imshow(bin);
toc;
and image for the detected hand is
Now when i use the code for detection in a video nothing is detected.
the code is this;
filename = 'hand_2.wmv';
video = vision.VideoFileReader(filename);
player = vision.DeployableVideoPlayer('Location', [10,100],'FrameRate',30);
while ~isDone(video)
img_orig = step(video);
% Capture the dimensions
height = size(img_orig,1);
width = size(img_orig,2);
%Initialize the output images
out = img_orig;
bin = zeros(height,width);
%Convert the image from RGB to YCbCr
img_uint8 = uint8(img_orig);
img_ycbcr = rgb2ycbcr(img_uint8);
Cb = img_ycbcr(:,:,2);
Cr = img_ycbcr(:,:,3);
%Detect Skin
[r,c,v] = find(Cb>=67 & Cb<=137 & Cr>=133 & Cr<=173);
numind = size(r,1);
%Mark Skin Pixels
for i=1:numind
out(r(i),c(i),:) = [0 0 255];
bin(r(i),c(i)) = 1;
end
% Detect radius
[x1,y1] = find(out(:,:,3) == 255, 1,'first');
[x2,y2] = find(out(:,:,3) == 255, 1, 'last');
if isempty(y1) && isempty(y2)
y1 = 2; y2 = 0;
end
% Detect Hand Center
hits = 0;
hitsArr = zeros(1,height);
for i = 1:height
hits = numel(find(bin(i,:) == 1));
hitsArr(i) = hits;
end
maxHitr = max(hitsArr);
y = find(hitsArr == maxHitr,1,'first');
hitsArr = zeros(1,width);
for i = 1:width
hits = numel(find(bin(:,i) == 1));
hitsArr(i) = hits;
end
maxHitc = max(hitsArr);
x = find(hitsArr == maxHitc,1,'first');
label = 'Hand';
position = [x y abs(y2-y1)/2; x y 1];
img_out = insertObjectAnnotation(img_orig,'Circle',position,label);
step(player, img_out);
end
release(video);
release(player);
What could be the problem?
댓글 수: 3
Awais Bilal
2015년 6월 20일
Yash Gajjar
2020년 1월 9일
I'm working on a similar project, but I need to use webcam and not video. I have tried changing out the image code to webcam compatible code but with no success. It would be great if you could help me with this issue...thx! -ygajjar005@gmail.com
답변 (1개)
Image Analyst
2014년 2월 16일
You might need to adjust your Cb and Cr thresholds. Otherwise use the debugger to figure out where it's coming out zeros when it should be giving something non-zero.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!