且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在MATLAB中检测实时视频流中的面部

更新时间:2022-10-16 07:46:09

功能图创建一个新图。在while循环之前移动此函数调用,结果应该显示在同一图中。


通过使用drawow方法,这已经解决了



drawow;

imshow(rgbframe)



PS如上所述在while循环开始之前采用数字

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

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.


By using drawnow method this is solved

drawnow;
imshow(rgbframe)

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