face_recognition安装记录

face_recognition安装记录

face_recognition使用dlib最先进的面部识别功能构建而成,并且该模型在LFW数据集中有99.38%的准确率。

1.环境

Win10+anaconda+python3.6

2.安装方式

有的教程说需要安装提前安装Cmake和boost,但是新版dlib是不需要boost的,我只提前安装了Cmake
流程:安装Cmake—>安装dlib—>安装face_recognition

安装Cmake

直接在Anaconda navigator里面安装就很方便,选择自己想要安装的环境,搜索选中Apply就好了

安装dlib:

①使用whl方式安装,anaconda的软件库里面是没有dlib的,需要自己去https://pypi.org/project/dlib/#history 下载一个适用于python3.6版本的whl文件,我下载的是19.8.1

②放在想要安装的环境中的Scripts文件夹下,我的是C:\Users\Krystal\Anaconda3\envs\pytorch\Scripts

③打开Anaconda prompt,激活想要安装dlib的环境

④命令行输入pip install dlib==19.8.1
安装成功

在这里插入图片描述
这里有很多教程是使用pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl,但我的就一直不行,显示没有此路径或文件,直接指定版本号反而很快就安装成功了

安装face_recognition

dlib安装好再安装face_recognition就简单很多了,继续输入命令pip install face_recognition

在这里插入图片描述
安装成功。如果显示ReadTimedoutError就再试一次。

3. 验证

命令行输入python,启动后输入import face_recognition不报错则为安装成功。
在这里插入图片描述
写给自己:心态要好,要努力,要上进,要毕业…┗( T﹏T )┛

这段 import cv2 import face_recognition import numpy as np from PIL import Image, ImageDraw,ImageFont video_capture = cv2.VideoCapture(r'C:/Users/ALIENWARE/123.mp4')#如果输入是(0)为摄像头输入 #现输入为MP4进行识别检测人脸 first_image = face_recognition.load_image_file("1.jpg") first_face_encoding = face_recognition.face_encodings(first_image)[0] Second_image = face_recognition.load_image_file("2.jpg") Second_face_encoding = face_recognition.face_encodings(Second_image)[0] third_image = face_recognition.load_image_file("3.jpg") third_face_encoding = face_recognition.face_encodings(third_image)[0] inside_face_encodings = [first_face_encoding,Second_face_encoding,third_face_encoding] inside_face_names = ['A','B','C'] face_locations = [] face_encodings = [] face_names = [] process_this_frame = True while True: ret, frame = video_capture.read() small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) rgb_small_frame = small_frame[:, :, ::-1] if process_this_frame: face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = [] for face_encoding in face_encodings: matches = face_recognition.compare_faces(inside_face_encodings, face_encoding) name = '未录入人脸' if True in matches: first_match_index = matches.index(True) name = inside_face_names[first_match_index] face_names.append(name) process_this_frame = not process_this_frame for (top, right, bottom, left), name in zip(face_locations, face_names): top *= 4 right *= 4 bottom *= 4 left *= 4 cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) img_pil = Image.fromarray(frame) draw = ImageDraw.Draw(img_pil) fontStyle = ImageFont.truetype("C:/Windows/Fonts/simsun.ttc", 32, encoding="utf-8") draw.text((left + 6, bottom - 6), name, (0, 200, 0), font=fontStyle) frame = np.asarray(np.array(img_pil)) cv2.imshow('face_out', frame) if cv2.waitKey(1) & 0xFF == ord('q'): #退出需要按下Q键否则内核会崩溃 break video_capture.release() cv2.destroyAllWindows()
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值