Python深度学习之人脸识别
我的环境是Python3.5,用的是Debian9,最好用linux,Windows没试过,不知道会不会报错。
pip3 install face_recognition
报错:CMake must be installed to build the following extensions: dlib
说明你需要安装CMake 命令如下
pip3 install cmake
然后你再安装
pip3 install face_recognition
会发现卡在了这里
Building wheels for collected packages: dlib
Running setup.py bdist_wheel for dlib ... |
如果没有报错的话,其实你只需要等一会就好了,我差不多等了十几分钟就安装成功了。
安装OpenCV
pip3 install opencv-python
识别人像的代码
import face_recognitionimport cv2
import numpy as np
image = face_recognition.load_image_file("timg.jpg")
face_locations = face_recognition.face_locations(image)
print(face_locations)
image = cv2.imread('timg.jpg')
for face_location in face_locations:
cv2.rectangle(image, (face_location[3],face_location[2]),(face_location[1], face_location[0]), (0, 0, 255), 2)
cv2.imwrite('out.jpg', image)
如果运行出opencv的错误,点这里
识别的头像
输出的结果
识别有多张脸的图片
还是用上面的代码,但是图片得对应上
原图
输出
更多的用法,点这里
以上是 Python深度学习之人脸识别 的全部内容, 来源链接: utcz.com/z/389086.html