2015-11-30 73 views
0

我使用此代碼作爲檢測視頻中手的膚色的起點。作爲我做的第一步,我使用imshow(segment)來顯示結果;在Matlab中使用函數。將二進制圖像顯示爲視頻的Matlab

這裏的代碼(網上查到)我不完全理解:

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 

這裏是結果: segmented skin

我遇到的問題是,我不瞭解如何通過使用vision.VideoPlayervision.VideoDeployer將視頻的二進制圖像顯示爲視頻,所以我可以在本例中顯示皮膚檢測視頻旁邊的原始結果:

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

回答

0

在你舉的例子,有兩個vision.VideoPlayer對象:一個用於顯示的原始視頻,以及一個用於顯示二進制圖像。您只需將二進制映像送入vision.VideoPlayer對象的step方法即可。