565| 1
|
[AI人工智能教程] LattePanda&AI-人脸识别门禁系统 |
本帖最后由 铁甲小宝 于 2020-9-3 17:33 编辑 LattePanda&AI-人脸识别门禁系统概述人脸识别,是基于人的脸部特征信息进行身份识别的一种生物识别技术。用摄像机或摄像头采集含有人脸的图像或视频流,并自动在图像中检测和跟踪人脸,进而对检测到的人脸进行脸部识别。 项目基础人脸识别硬件准备:AI主控:LattePanda 人脸信息录入:1、双击桌面上的“startpage.sh”,打开JupyterLab,切换到“home/lattepanda/桌面/LattePanda&AI项目实战/”目录下,如下图,检查一下项目必需的3个文件; 样例代码:
6、选择效果最好的一张,重命名为此人的姓名; 程序编写:1、双击打开“人脸识别.ipynb”; [mw_shl_code=python,false]#导入人脸识别模块 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()[/mw_shl_code] 2、运行程序,当执行到最后一个单元格时,会打开交互窗口。 项目进阶人脸识别门禁系统如果让人脸作为门禁系统的钥匙,会使我们的生活更方便快捷。当识别到主人的人脸时,灯带亮绿灯,表示准许进入;否则显示红灯。 硬件准备:主控:Arduino UNO、IO 传感器扩展板 V7.1 硬件连接图:
程序编写:双击打开“人脸识别_灯带.ipynb”; [mw_shl_code=python,false]#导入人脸识别模块 from faceRecognition import * import time from pinpong.board import Board,Pin,NeoPixel NEOPIXEL_PIN = Pin.D7 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()[/mw_shl_code] 运行效果:当识别到已知人脸时,灯带的第一个灯亮绿色; |
© 2013-2021 Comsenz Inc. Powered by Discuz! X3.4 Licensed