image thumbnail

videoioPlayer

by

 

16 Feb 2012 (Updated )

This package contains a videoplayer class capable of viewing and processing video files in real-time

demo2(fname)
function vp = demo2(fname)

if ~exist('fname','var')
    fname = which('traffic.avi') ;
end

vp = videoioPlayer(fname,'ffmpegDirect','position',[500 0],'title',mfilename) ;
vp.filter = carDetect ;


function fcn = carDetect

darkCarValue = 50;
sedisk = strel('disk',2);
fcn = @(x)carDetectFcn(x,darkCarValue,sedisk) ;


function outImg = carDetectFcn(inImg,darkCarValue,sedisk)

outImg = inImg ;
inImg = bwareaopen(imopen(imextendedmax(rgb2gray(inImg), darkCarValue), sedisk), 150);
stats = regionprops(inImg, {'Centroid','Area'});
%outImg = inImg ;

if ~isempty([stats.Area])
    areaArray = [stats.Area];
    [~,idx] = max(areaArray);
    c = stats(idx).Centroid;
    c = floor(fliplr(c));
    width = 2;
    row = c(1)-width:c(1)+width;
    col = c(2)-width:c(2)+width;
    
    outImg(row,col,1) = 255;
    outImg(row,col,2) = 0;
    outImg(row,col,3) = 0;
end

Contact us