Face Detection In Video

2 views (last 30 days)
Wong  Ting Yi
Wong Ting Yi on 26 May 2015
Answered: Dima Lisin on 18 Jun 2015
Greeting to all, I'm now working on Viola Jones face detection which in frame by frame. But now the problem i face are is hard to storing the face segmented in a specified variables. Let's said, there're 3 faces was detected in this face detection where we named them as face 1 to face 3 and stored them into variable bbox(1,:) to bbox(3,:). but there're only 1 face remaining for next frame which was face 3. In this case, the face3 will store at bbox(1,:) instead of bbox(3,:). What if i want to empty the variable of bbox(1,:) and bbox(1,:) when face1 and face2 were disappeared. Which meant if there's another new face detected or face1 re-detect, it will direct store it into another new array of this variable. This problem already costs me for few days and is still surrounded. I'm attached my code at below and hope someone can help me to solve this ‘BIG PROBLEM' for me. Thanks to those who willing to review my question.
clear; faceDetector = vision.CascadeObjectDetector();
bbox = [100 100 100 100];
bboxx0 = [100 100 100 100];
bboxx1 = [100 100 100 100];
bbox1 = [100 100 100 100];
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ... 'ROI', [1 1 640 480], ... 'ReturnedColorSpace', 'rgb' );
set(vidDevice.DeviceProperties, 'FrameRate', '30');
boxInserter = vision.ShapeInserter('BorderColor','Custom',... 'CustomBorderColor',[255 255 0]);
textInserter = vision.TextInserter('%d','LocationSource','Input port','Color',[255, 255, 0],'FontSize',12);
nFrame = 300; max =1;
vidInfo = imaqhwinfo(vidDevice);
vidHeight = vidInfo.MaxHeight;
vidWidth = vidInfo.MaxWidth;
videoPlayer = vision.VideoPlayer('Position',[300 100 640+30 480+30]);
mov(1:nFrame) = ... struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),... 'colormap', []);
mov1(1:nFrame) = ... struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),... 'colormap', []);
for k = 1:nFrame
tic;
videoFrame = step(vidDevice);
bbox = 5 * faceDetector.step(imresize(videoFrame, 1/5));
numface = size(bbox,1);
for m = 1: size(bbox,1)
if ~isempty(bbox)
bboxx0(m,1) = bbox(m,1)+bbox(m,4)*0.15;
bboxx0(m,2) = bbox(m,2)+bbox(m,4)*0.45;
bboxx0(m,3) = (bbox(m,4)/5);
bboxx0(m,4) = (bbox(m,3)/5);
bboxx1(m,1) = (bbox(m,1)+bbox(m,4)*0.6);
bboxx1(m,2) = (bbox(m,2)+bbox(m,4)*0.45);
bboxx1(m,3) = (bbox(m,4)/5) ;
bboxx1(m,4) = (bbox(m,3)/5) ;
end
end
videoOut = step(boxInserter, videoFrame, bbox);
release(boxInserter);
for m = 1:numface
strings =m;
videoOut = step(textInserter,videoOut,int8(strings),[bbox(m,1)+5 bbox(m,2)+5]);
release(textInserter);
end
for m = 1: numface
mov1(m,k).cdata = imcrop(videoOut,bboxx0(m,:)); % right
mov(m,k).cdata = imcrop(videoOut,bboxx1(m,:)); % left
end
if (size(bboxx0,1)>numface)
for n = 0: size(bboxx0,1)-numface
bboxx0(size(bboxx0,1)-n,:) = [];
bboxx1(size(bboxx1,1)-n,:) = [];
break;
end
end
videoOut = step(boxInserter, videoOut,bboxx0);
release(boxInserter);
videoOut = step(boxInserter, videoOut, bboxx1);
step(videoPlayer, videoOut);
x1(k) = toc;
end
x = sum(x1);
release(videoPlayer);
release(vidDevice);

Answers (1)

Dima Lisin
Dima Lisin on 18 Jun 2015
There is an example showing how to detect and track multiple faces in video, which may be helpful.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!