其他分享
首页 > 其他分享> > 【数字图像处理】本地摄像头人脸识别

【数字图像处理】本地摄像头人脸识别

作者:互联网

一、摄像头调用

imaqhwinfo命令是帮助我们获得电脑的摄像头信息

Camera_info=imaqhwinfo %#ok<NOPTS>

如果:

这个警告说明你的Matlab没有安装摄像头插件

点击黄色警告带下滑线的 Add-Ons Explorer 或者         (中文)        进行安装

(安装Matlab附加功能包需要注册matlab账号(free),附属功能很强大建议整一个)

点击需要的(不知道哪个就最多下载的那个试试)

等待安装就可以。。。

(matlab查看摄像头详细信息 请看 https://blog.csdn.net/hmg25/article/details/4126122 

二、调用摄像头

imaq.VideoDevice帮助我们每次从视频设备获取一帧

VideoDevice=imaq.VideoDevice;

preview将摄像头显示

preview(VideoDevice);

创建一个容器将脸部放入其中

Face_frame=[100 100 100 100];

Rectangular region of interest within image I, specified as a four-element vector, [x y width height].——matlab帮助

(图像I内感兴趣的矩形区域,指定为一个四元向量,[x y宽高]。  翻译引用:网易有道词典)

引用工具箱功能用于人脸识别及捕捉

FrameInserter=vision.ShapeInserter;
FaceDetector=vision.CascadeObjectDetector();
CameraDetector_info=imaqhwinfo(VideoDevice);

(     vision.ShapeInserter

——The ShapeInserter object can draw multiple rectangles, lines, polygons, or circles in a 2-D grayscale or truecolor RGB image. The output image can then be displayed or saved to a file.

——ShapeInserter对象可以绘制多个矩形、直线、多边形或二维灰度或真彩色RGB图像中的圆圈。 输出图像然后可以显示或保存到一个文件。     )  

(     vision.CascadeObjectDetector()

——Detect objects using the Viola-Jones algorithm

——使用Viola-Jones算法检测对象      )

参数设置

nFrame=300;
VideoHight=CameraDetector_info.MaxHeight;
VideoWidth=CameraDetector_info.MaxWidth;
VideoPlayer = vision.VideoPlayer;

逐帧检测

for f = 1:nFrame 
    VideoFrame = step(VideoDevice); 
    Face_frame = 4 * FaceDetector.step(imresize(VideoFrame, 1/4)); 
    VideoOut = step(FrameInserter, VideoFrame, Face_frame); 
    step(VideoPlayer, VideoOut);
end

图片来自网络,侵删

动态识别结果

释放摄像头资源占用!!!(可能很重要,可能不需要,这可能会导致摄像头第二次运行不出来)

imaqreset

 

 

 

 

 

 

 

参考:matlab-调用摄像头人脸识别 - hyb965149985 - 博客园 (cnblogs.com)

标签:人脸识别,VideoDevice,数字图像处理,step,摄像头,100,vision,matlab
来源: https://www.cnblogs.com/ShuyaoDong/p/16263672.html