概述
人脸识别,是基于人的脸部特征信息进行身份识别的一种生物识别威廉希尔官方网站
。用摄像机或摄像头采集含有人脸的图像或视频流,并自动在图像中检测和跟踪人脸,进而对检测到的人脸进行脸部识别。

本项目中我们将实现摄像头人脸识别效果,包含人名标签和识别框,并结合灯带的亮灯状态制作人脸识别门禁系统。
(最终效果视频)
项目基础
人脸识别
硬件准备:
AI主控:LattePanda
输入输出设备:5英寸显示屏、键盘、鼠标、摄像头
人脸信息录入:
1、双击桌面上的“startpage.sh”,打开JupyterLab,切换到“home/lattepanda/桌面/LattePanda&AI项目实战/”目录下,如下图,检查一下项目必需的3个文件;

2、双击进入“图片拍摄”文件夹;

3、双击打开程序,修改拍摄的照片数量,例如for index in range(3);

样例代码:

4、选择无其他人、无杂物的背景,正眼看着摄像头,然后运行程序,拍摄的图片会在程序同目录下依次出现;

5、双击图片查看拍摄效果;
6、选择效果最好的一张,重命名为此人的姓名;

7、将照片复制到“LattePanda&AI-人脸识别门禁系统”文件夹下。

程序编写:
1、双击打开“人脸识别.ipynb”;

样例代码:


复制代码 隐藏代码
#导入人脸识别模块
from
faceRecognition import *
#人脸检测与识别文件调用
faceDetectorPath
=
"face-detection-retail-0005.xml"
landmarksPath
=
"landmarks-regression-retail-0009.xml"
faceReidentificationPath
=
"face-reidentification-retail-0095.xml"
#调用训练模型文件
model
= Model()
model
.load(faceDetectorPath = faceDetectorPath,
landmarksPath
= landmarksPath,
faceReidentificationPath
= faceReidentificationPath)
#初始化摄像头与窗口
camera
= Camera()
screen
= Screen(
"人脸识别门禁系统"
, (
0
,
0
,
0
))
#打开手写数字交互窗口,按下“Q”键退出窗口
if_run
=
1
while
(if_run ==
1
):
#从摄像头获取图片
image
= camera.read(flip = False)
#图片剪裁
image
= model.clipResizeFrame(image)
screen
.clear()
#获取人脸识别结果并在屏幕上显示识别标签
results
= model.predict(image)
screen
.putImage(image,
80
,
0
,
640
,
480
)
for
roi, landmarks, identity in zip(*results):
x
, y = roi.position
w
, h = roi.size
screen
.putTag(identity, x+
80
, y, w, h, bg=(
0
,
255
,
0
))
#打开与显示交互窗口,如果按下Q键,将无法进入下一次while循环
if
screen.show():
if_run
=
0
screen
.quit()
复制代码
2、运行程序,当执行到最后一个单元格时,会打开交互窗口。
未识别到人脸:

检测到未知人脸:

识别到已知人脸,并显示此人姓名:

3、按键盘上的“Q”键可退出交互窗口。
项目进阶
人脸识别门禁系统
如果让人脸作为门禁系统的钥匙,会使我们的生活更方便快捷。当识别到主人的人脸时,灯带亮绿灯,表示准许进入;否则显示红灯。
硬件准备:
主控:Arduino UNO、IO 传感器扩展板 V7.1
模块:WS2812 RGB 全彩灯带
硬件连接图:

*WS2812上有7个RGB灯,程序中的np[0]表示第一个灯,程序中的np[1]表示第二个灯。
程序编写:
双击打开“人脸识别_灯带.ipynb”;

样例代码:



复制代码 隐藏代码
#导入人脸识别模块
from
faceRecognition import *
import
time
from
pinpong.board import Board,Pin,NeoPixel
NEOPIXEL_PIN
= Pin.D
7
PIXELS_NUM
=
1
#灯数,如果需要多个灯亮,请改此数值
#初始化,选择板型和端口号
Board
(
"uno"
,
"/dev/ttyUSB0"
).begin()
np
= NeoPixel(Pin(NEOPIXEL_PIN), PIXELS_NUM) #np[
0
]表示第一个灯,np[
1
]表示第二个灯,以此类推
#人脸检测与识别文件调用
faceDetectorPath
=
"face-detection-retail-0005.xml"
landmarksPath
=
"landmarks-regression-retail-0009.xml"
faceReidentificationPath
=
"face-reidentification-retail-0095.xml"
#调用训练模型文件
model
= Model()
model
.load(faceDetectorPath = faceDetectorPath,
landmarksPath
= landmarksPath,
faceReidentificationPath
= faceReidentificationPath)
#初始化摄像头与窗口
camera
= Camera()
screen
= Screen(
"人脸识别门禁系统"
, (
0
,
0
,
0
))
#打开手写数字交互窗口,按下“Q”键退出窗口
if_run
=
1
led
=
0
count
=
0
while
(if_run ==
1
):
#从摄像头获取图片
image
= camera.read(flip = False)
#图片剪裁
image
= model.clipResizeFrame(image)
screen
.clear()
#获取人脸识别结果并在屏幕上显示识别标签
results
= model.predict(image)
screen
.putImage(image,
80
,
0
,
640
,
480
)
for
roi, landmarks, identity in zip(*results):
x
, y = roi.position
w
, h = roi.size
screen
.putTag(identity, x+
80
, y, w, h, bg=(
0
,
255
,
0
))
#count>30,修改30可调节切换灯颜色的速度
if
identity !=
"未知人脸"
and count>
30
:
np
[
0
] = (
0
,
255
,
0
) #设置第一个灯亮绿色
#np[1] = (0, 255 ,0) #设置第二个灯亮绿色
count
=
0
elif
identity ==
"未知人脸"
and count>
30
:
np
[
0
] = (
255
,
0
,
0
) #设置第一个灯亮红色
#np[1] = (255, 0 ,0) #设置第二个灯亮红色
count
=
0
count
+=
1
#打开与显示交互窗口,如果按下Q键,将无法进入下一次while循环
if
screen.show():
if_run
=
0
screen
.quit()
复制代码
运行效果:
当识别到已知人脸时,灯带的第一个灯亮绿色;

当屏幕中没有人脸或者是未知人脸时,灯带的第一个灯亮红色。

本文转载至:DF创客社区
原文链接:https://mc.dfrobot.com.cn/thread-306871-1-1.html
-
英特尔
+关注
关注
61文章
9953浏览量
171700 -
操作系统
+关注
关注
37文章
6808浏览量
123291 -
开发板
+关注
关注
25文章
5035浏览量
97383 -
Win10
+关注
关注
2文章
710浏览量
39980
发布评论请先 登录
相关推荐
如何选择合适的人脸门禁系统?人脸打卡门禁哪款好?

如何提升人脸门禁一体机的识别准确率?

隧道口门禁人脸识别是一种先进的安全管理威廉希尔官方网站

如何设计人脸识别的神经网络



评论