基于matlab的人脸识别 博客,matlab-调用摄像头人脸识别

----------------------------边学边写边学习-------------------------------------

版本:2014a

调用摄像头

a = imaqhwinfo

如果出现下面的警告说明你没安装扩展工具。

警告: No Image Acquisition adaptors found. Image acquisition adaptors may be available as downloadable support packages. Open Support Package Installer to install additional vendors.

这时候Support Package Installer在MATLAB里面有下划线,然后你点开它,MATLAB会提供大概13个软件包,这时候选择OS Generic Video Interface下载安装就OK了 (要求注册账号,随便用个邮箱注册下就可以了,不需要付费)。

下面就是调用笔记本电脑摄像头并打开图像

(%如果使用USB摄像头,一般为2,笔记本自带摄像头为1)

vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ...

'ROI', [1 1 640 480], ...

'ReturnedColorSpace', 'rgb' );

preview(vidDevice);

人脸检测我们用的是matlab的机器视觉工具箱(瞬间觉得matlab真心强大)

VJ算法的目的是检测人脸,但是其思想同样可以用于检测其他物体,只需进行训练即可。

VJ算法在Matlab里面实现的时候,已经训练好了正脸、侧脸、上半身、眼睛、嘴、鼻子,这些都是可以直接检测,不需训练,直接调用CascadeObjectDetector函数即可。

下面是检测人脸和上半身的例子

% Example 1: Face detection

% ----------------------------

faceDetector = vision.CascadeObjectDetector; % Default: finds faces

I = imread('visionteam.jpg');

bboxes = step(faceDetector, I); % Detect faces

% Annotate detected faces

IFaces = insertObjectAnnotation(I, 'rectangle', bboxes, 'Face');

figure, imshow(IFaces), title('Detected faces');

% Example 2: Upper body detection

% --------------------------------------

bodyDetector = vision.CascadeObjectDetector('UpperBody');

bodyDetector.MinSize = [60 60];

bodyDetector.MergeThreshold = 10;

I2 = imread('visionteam.jpg');

bboxBody = step(bodyDetector, I2); % Detect upper bodies

% Annotate detected upper bodies

IBody = insertObjectAnnotation(I2, 'rectangle', ...

bboxBody, 'Upper Body');

figure, imshow(IBody), title('Detected upper bodies');

至于调用摄像头进行人脸识别,肯定是 调用摄像头的过程中对每一帧图像分别进行识别,然后再在图像中框出来。

这就要求 速度 要足够快。所以检测的时候就要压缩你图像的像素了。

下面放代码

faceDetector = vision.CascadeObjectDetector(); %enable viola jones algorithm

bbox = [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;

vidInfo = imaqhwinfo(vidDevice);

vidHeight = vidInfo.MaxHeight;

vidWidth = vidInfo.MaxWidth;

videoPlayer = vision.VideoPlayer('Position',[300 100 640+30 480+30]);

for k = 1:nFrame % start recording with 300 frames

%tic; % timer start

videoFrame = step(vidDevice); % enable the image capture by webcam

bbox = 4 * faceDetector.step(imresize(videoFrame, 1/4)); % boost video's fps

videoOut = step(boxInserter, videoFrame, bbox); % highlight the boxes of face at video

%release(boxInserter);

step(videoPlayer, videoOut); % display the video live in video player

end

一共执行了300帧,下面放图。

53be3414209de351247e11e69c5843fc.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值