我是如何用树莓派 + Docker 轻松实现人脸识别应用的? | 您所在的位置:网站首页 › docker默认cpu › 我是如何用树莓派 + Docker 轻松实现人脸识别应用的? |
点击▲关注 “CU技术社区” 置顶公众号 人脸识别技术已经被广泛应用在众多场景中。今天我们将利用Docker容器在树莓派上快速打造一个人脸识别应用。本文使用 https://github.com/ageitgey/facerecognition 开源框架,基于 dlib(Deep Metric Learning)支持人脸识别功能。dlib 在Labeled Faces in the Wild 测试基准上的准确率达到 99.38%。facerecognition的应用开发极为简单,只用几行 Python 命令行就可以轻松实现人脸识别应用,而且也提供了树莓派的支持。在Raspberry Pi 2+ 平台安装face_recognition的指南如下:https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65树莓派是Geek们爱的开发板,其原因就在于成熟的软件生态和丰富的I/O接口,然而在树莓派上搞深度学习应用开发并非易事。很多包需要下载编译,以孱弱的Raspberry Pi编译应用,需要极大的耐心。 然而开源的深度学习框架很多,不同类库的依赖不同,有些会互相冲突,比如有些需要Python 2.7,有些则依赖 3.x。虽然我们可以用virtualenv对Python环境进行隔离,但是对于一些系统级的依赖冲突就不好办了。在漫长构建中遇到依赖导致编译失败,让人非常有挫败感。 如果需要在另外一块板上部署相同应用,整个过程需要重新来过。 下面我们将利用Docker来构建打包应用镜像,这样可以一次构建到处运行,也可以充分利用Dockerfile自带的分层能力,可以方便地调整依赖包,这样在开发部署过程中格外高效。 树莓派上部署人脸识别应用# This is a demo of running face recognition on a Raspberry Pi.# This program will print out the names of anyone it recognizes to the console.# To run this, you need a Raspberry Pi 2 (or greater) with face_recognition and# the picamera[array] module installed.# You can follow this installation instructions to get your RPi set up:# https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65import face_recognitionimport picameraimport numpy as npknown_face_encodings = []names = []def load_face_encoding(name, file_name): image = face_recognition.load_image_file(file_name) face_encoding = face_recognition.face_encodings(image)[0] known_face_encodings.append(face_encoding) names.append(name)# Get a reference to the Raspberry Pi camera.# If this fails, make sure you have a camera connected to the RPi and that you# enabled your camera in raspi-config and rebooted first.camera = picamera.PiCamera()camera.resolution = (320, 240)output = np.empty((240, 320, 3), dtype=np.uint8)# Load a sample picture and learn how to recognize it.print("Loading known face image(s)")load_face_encoding("Yi Li", "yili.jpg")load_face_encoding("Zhang Kai", "zhangkai.jpg")load_face_encoding("Che Yang", "cheyang.jpg")# Initialize some variablesface_locations = []face_encodings = []while True: print("Capturing image.") # Grab a single frame of video from the RPi camera as a numpy array camera.capture(output, format="rgb") # Find all the faces and face encodings in the current frame of video face_locations = face_recognition.face_locations(output) print("Found {} faces in image.".format(len(face_locations))) face_encodings = face_recognition.face_encodings(output, face_locations) # Loop over each face found in the frame to see if it's someone we know. for face_encoding in face_encodings: # See if the face is a match for the known face(s) matches = face_recognition.face_distance(known_face_encodings, face_encoding) name = "" min_distance = min(matches) if min_distance |
CopyRight 2018-2019 实验室设备网 版权所有 |