0

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:

http://uk.mathworks.com/help/vision/examples/motion-based-multiple-object-tracking.html?searchHighlight=multiple%20motion%20detection

Dima
  • 38,860
  • 14
  • 75
  • 115
user123
  • 1
  • 2

1 Answers1

0

In the example you cited, there are two vision.VideoPlayer objects: one for displaying the original video, and one for displaying the binary images. You simply feed the binary images into the step method of the vision.VideoPlayer object.

Dima
  • 38,860
  • 14
  • 75
  • 115