在MATLAB中检测实时视频流中的面部 [英] Detecting Faces in live video stream in MATLAB

查看:421
本文介绍了在MATLAB中检测实时视频流中的面部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我对MATLAB很新,事实上它只用了一天左右。我正在尝试使用现有的函数实现面部检测,我能够遇到matlab提供的代码。它工作得很好,但我想改变它以检测实时视频流中的面孔下面是我的代码。

清除所有
clc
%使用Viola-Jones算法检测对象

%检测Face
FDetect = vision.CascadeObjectDetector;

%阅读输入图像
vidDevice = imaq.VideoDevice('winvideo',1,'YUY2_640x480',...%获取输入视频流
'ROI',[ 1 1 640 480],...
'RevertnedColorSpace','rgb');
vidInfo = imaqhwinfo(vidDevice);
nFrame = 0
while(nFrame< 20)
rgbFrame = step(vidDevice); %获取单帧
rgbFrame = flipdim(rgbFrame,2);
%根据对象数返回Bounding Box值
BB = step(FDetect,rgbFrame);

数字,
imshow(rgbFrame);对于i = 1,
持有
:尺寸(BB,1)
矩形('位置',BB(i,:),'LineWidth',5,'LineStyle',' - , 'EdgeColor', 'R');
结束
title('人脸检测');
nFrame = nFrame + 1;
结束
延期;





它的作用是我的网络摄像头正常运行并正确检测到脸部但是而不是每个帧都有一个数字它创建一个新的数字:)。我试图使用函数刷新(图)但没有正确。我很确定我是以一种可怕的方式做到这一点,这就是为什么我是在这里寻求帮助。



无论如何谢谢

解决方案

功能图创建一个新图。在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


这篇关于在MATLAB中检测实时视频流中的面部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆