python 实现摄像头人脸识别

1、window安装dlib、face_recognition

ace_recognition简介
face_recognition是Python的一个开源人脸识别库,支持Python 3.3+和Python 2.7。引用官网介绍:

Recognize and manipulate faces from Python or from the command line with the world's simplest face recognition library.

安装配置
我目前的开发环境是,操作系统:Win10,Python3.6:Anaconda集成开发环境。在安装 face_recognition的过程中花费了一些时间,所以把安装过程记录下来。

使用pip安装

   pip install face_recognition
如果安装失败了,那基本上是因为依赖的dlib库安装失败了,需要手动安装。网上介绍的安装dlib库的方法大都很复杂,需要下载源代码,然后手动编译。

安装dlib
1、下载
dlib-19.8.1-cp36-cp36m-win_amd64.whl

2、安装

    pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl
    pip install dlib

    pip show dlib   #验证dlib是否安装成功
安装face_recognition_models
1、下载 face_recognition_models 0.3.0

2、解压压缩包,进入face_recognition_models-0.3.0目录,安装

    python setup.py install
    pip show face_recognition_models
安装face_recognition
1、下载 face_recognition 1.0.0
2、解压压缩包,进入face_recognition目录,安装

    python setup.py install
    pip show face_recognition

 2、下载代码

           https://github.com/ageitgey/face_recognition.git

3、运行代码

          facerec_from_webcam.py

 因为原有代码仅对摄像头进行读取,修改以下文件可以读取摄像头文件

# video_capture = cv2.VideoCapture("hamilton_clip.mp4")
video_capture = cv2.VideoCapture("rtsp://192.168.1.11:444/subtype=1&subchannanel=1")
# video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
# Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]

# Load a second sample picture and learn how to recognize it.
biden_image = face_recognition.load_image_file("biden.jpg")
biden_face_encoding = face_recognition.face_encodings(biden_image)[0]

sungebingimage = face_recognition.load_image_file("sungebing.jpg")
sungebing_face_encoding = face_recognition.face_encodings(sungebingimage)[0]

ssjimage = face_recognition.load_image_file("ssj.jpg")
ssjimage_face_encoding = face_recognition.face_encodings(ssjimage)[0]
# Create arrays of known face encodings and their names
known_face_encodings = [
    obama_face_encoding,
    biden_face_encoding,
    ssjimage_face_encoding,
    sungebing_face_encoding
]
known_face_names = [
    "Barack Obama",
    "Joe Biden",
    "sun shengjie",
    "sungebing"
]

 dlib-19.8.1-cp36-cp36m-win_amd64.whl

face_recognition_models 0.3.0

face_recognition 1.0.0

4、也可以在项目的最后将摄像头读取的视频转为视频流输出,通过web显示。

相关推荐