「图像处理」使用Python+Openface实现人脸识别与关键点(landmarks)检测 |
您所在的位置:网站首页 › 人脸定位跟踪软件下载安装 › 「图像处理」使用Python+Openface实现人脸识别与关键点(landmarks)检测 |
1、如何在Python上安装OpenFace
下载安装
1、首先需要下载OpenFace源码: (Anaconda、Git等自行提前安装) git clone https://github.com/cmusatyalab/openface.git2、接着进入openface路径 cd openface3、执行: pip install -r requirements.txt4、执行: python setup.py install需要说明的是,第3步,自动安装可能会很慢或出问题,可以(参考该文件内容)手动安装依赖项。 安装完之后,可以在控制台中,进入python环境,然后导入openface的包看是否报错 可能会有确实其他包的报错,比如报缺少“opencv_python”,缺什么就装什么即可,知道不再报错。 模型下载进入 cd models运行 ./get-models.sh 或者手动下载(参考该文件内容): 1、http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 解压到:【*openface\models\dlib】目录下 2、https://storage.cmusatyalab.org/openface-models/nn4.small2.v1.t7 https://storage.cmusatyalab.org/openface-models/celeb-classifier.nn4.small2.v1.pkl 这两个放到【*openface\models\openface】目录下 2、用opencv实现一个实时摄像头获取画面的程序 import threading import cv2 class OpcvCapture(threading.Thread): def __init__(self, win_name, cam_name): super().__init__() self.cam_name = cam_name self.win_name = win_name def run(self): capture = cv2.VideoCapture(self.cam_name) while (True): # 获取一帧 ret, frame = capture.read() cv2.imshow(self.win_name, frame) cv2.waitKey(1) if __name__ == "__main__": camera1 = OpcvCapture("camera1", 1) camera1.start() run_code = 0路径根据实际进行配置,或将【models】文件夹复制到项目所在位置 import os import openface fileDir = os.path.dirname(os.path.realpath(__file__)) modelDir = os.path.join(fileDir, 'models') dlibModelDir = os.path.join(modelDir, 'dlib') align = openface.AlignDlib(os.path.join(dlibModelDir, "shape_predictor_68_face_landmarks.dat")) 添加检测算法并绘制点 def _detector(self, frame, mirror=False): show_img = cv2.flip(frame, flipCode=1) if mirror else frame rects = align.getAllFaceBoundingBoxes(show_img) if len(rects) > 0: bb = align.findLandmarks(show_img, rects[0]) for pt in bb: cv2.circle(show_img, pt, 3, [0, 0, 255], thickness=-1) return show_img 在获取到的帧上进行调用在第二节的摄像头画面获取的程序中,每获取到一帧图像后调用检测算法,将返回的结果进行显示: #摄像头实时画面线程类的部分代码 def run(self): capture = cv2.VideoCapture(self.cam_name) while (True): # 获取一帧 ret, frame = capture.read() # 获取的帧送入检测,绘制检测结果后返回,自拍模式做镜像 show_img = self._detector(frame, mirror=True) cv2.imshow(self.win_name, show_img) cv2.waitKey(1) 最终效果:
|
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |