Click here to Skip to main content
15,922,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am very new to MATLAB in fact its been only a day or so.I am trying to implement face detection using exsisting functions and i am able to come across code provided by matlab. It works perfectly fine but i want to change it to detect faces in live video stream below is my code.
 clear all
clc
%Detect objects using Viola-Jones Algorithm

%To detect Face
FDetect = vision.CascadeObjectDetector;

%Read the input image
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ... % Acquire input video stream
                    'ROI', [1 1 640 480], ...
                    'ReturnedColorSpace', 'rgb');
vidInfo = imaqhwinfo(vidDevice);
nFrame = 0
while(nFrame<20)
rgbFrame = step(vidDevice); % Acquire single frame
rgbFrame = flipdim(rgbFrame,2);
%Returns Bounding Box values based on number of objects
BB = step(FDetect,rgbFrame);

 figure,
 imshow(rgbFrame);
 hold on
for i = 1:size(BB,1)
    rectangle('Position',BB(i,:),'LineWidth',5,'LineStyle','-','EdgeColor','r');
end
title('Face Detection');
nFrame=nFrame+1;
end
hold off;


What it does is that my webcam gets on correctly and detects face correctly but instead of having one figure for every frame it creates a new figure :).I tried to use the function refresh(figure) but not getting it right.I am pretty sure i am doing it in a horrible way so that is why i am here to seek help.

Thanks anyways
Posted
Updated 21-Feb-14 18:22pm
v2

The function figure creates a new figure. Move this function call before the while loop and the results should be shown in the same figure.
 
Share this answer
 
Comments
loraloper_22 27-Feb-14 2:56am    
HINO even with that it does not help.Although yes taking teh figure out of while loop is necessary but it does not give the out put still the figure box does not get updated.Thanks anyways
By using drawnow method this is solved

drawnow;
imshow(rgbframe)

P.S as suggested above take the "figure"before start of the while loop
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900