I'm using this code as a starting point to detect the skin color of a hand in a video. as the first step I've manged to do that and display the result by using the imshow(segment); function in Matlab.
here's the code (found online) i don't fully understand:
function SkinDetection()
obj = VideoReader('CloseupHandVid.mp4');
nframes = read(obj, inf);
nframes = get(obj, 'NumberOfFrames');
I = read(obj, 1);
for k = 1 : nframes
singleFrame = read(obj, k);
Skin(:,:,:,k) = singleFrame;
whos v
I=double(singleFrame);
[hue,s,v]=rgb2hsv(I);
cb = 0.148* I(:,:,1) - 0.291* I(:,:,2) + 0.439 * I(:,:,3) + 128;
cr = 0.439 * I(:,:,1) - 0.368 * I(:,:,2) -0.071 * I(:,:,3) + 128;
[w h]=size(I(:,:,1));
for i=1:w
for j=1:h
if 140<=cr(i,j) && cr(i,j)<=165 && 140<=cb(i,j) && cb(i,j)<=195 && 0.01<=hue(i,j) && hue(i,j)<=0.1
segment(i,j)=1;
else
segment(i,j)=0;
end
end
end
imshow(segment);
end
end
and here is the result: segmented skin
the problem i'm having is that i can't figure out how to display the binary images as a video by using either vision.VideoPlayer or vision.VideoDeployer so i can display the result of the skin detected video next to original like in this example: