Python实现多人脸识别系统

冷不防 2023-10-15 14:38 83阅读 0赞

资源下载地址:https://download.csdn.net/download/sheziqiong/88284343 资源下载地址:https://download.csdn.net/download/sheziqiong/88284343 Face recognition from camera with Dlib

Introduction

调用摄像头进行人脸识别, 支持多张人脸同时识别

  1. Tkinter 人脸录入界面, 支持录入时设置 (中文) 姓名

    652b3c600456fe4d89ae7a48aee6e91e.png{.align-center
    width=“1000px”}

  2. 简单的 OpenCV 摄像头人脸录入界面

    a0cfd94099a8ab0722f8c9d1e5f9601c.png{.align-center
    width=“1000px”}

    离摄像头过近, 人脸超出摄像头范围时, 会有 “OUT OF RANGE” 提醒

    外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传{.align-center
    width=“1000px”}

  3. 提取特征建立人脸数据库
  4. 利用摄像头进行人脸识别

    face_reco_from_camera.py, 对于每一帧都做检测识别

    外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传{.align-center width=“1000px”}

    face_reco_from_camera_single_face.py, 对于人脸<=1,
    只有新人脸出现才进行再识别来提高 FPS

    d73f40da344961c8641d13fa6fe6509d.png{.align-center
    width=“1000px”}

    face_reco_from_camera_ot.py, 利用 OT 来实现再识别提高 FPS

    外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传{.align-center
    width=“1000px”}

    定制显示名字, 可以写中文

    外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传{.align-center
    width=“1000px”}

关于精度 :

  • 当使用 0.6 的距离阈值时,dlib 模型在标准 LFW 人脸识别基准上获得 99.38% 的精度。

关于算法

  • 基于 Residual Neural Network / 残差网络的 CNN 模型;
  • This model is a ResNet network with 29 conv layers.

本质上是 ResNet-34 网络的一个版本,来自 He,Zhang,Ren 和 Sun 的论文 Deep Residual Learning for Image Recognition,去掉了几层,每层过滤器的数量减少了一半。

概述

此项目中人脸识别的实现流程 (no OT, 每一帧都进行检测 + 识别)

1e19eb240228fce700a157136719515e.png{.align-center width=“1000px”}

实现流程 (with OT, 初始帧进行检测 + 识别, 后续帧检测 + 质心跟踪) / OT used:

74034cf675ef25a9ca2812dd8afe24cb.png{.align-center
width=“1000px”}

如果利用 OT 来跟踪, 可以大大提高 FPS,因为做识别时候需要提取特征描述子的耗时很多

Steps

  1. / Git clone source code

    ```{.bash}
    git clone https://git.writebug.com/goodwill/DlibFaceRecognition.git

    1. 安装依赖库

      ```{.bash}
      pip install -r requirements.txt

  2. 进行人脸信息采集录入,

    1. # Install Tkinter
    2. sudo apt-get install python3-tk python3-pil python3-pil.imagetk
    3. python3 get_faces_from_camera_tkinter.py
  3. 进行人脸信息采集录入, OpenCV GUI

    1. python3 get_face_from_camera.py
  4. 提取所有录入人脸数据存入 features_all.csv

    1. python3 features_extraction_to_csv.py
  5. 调用摄像头进行实时人脸识别

    1. python3 face_reco_from_camera.py
  6. 对于人脸数<=1, 调用摄像头进行实时人脸识别

    1. python3 face_reco_from_camera_single_face.py
  7. 利用 OT 算法, 调用摄像头进行实时人脸识别

    1. python3 face_reco_from_camera_ot.py

源代码相关

代码结构 :

  1. .
  2. ├── get_faces_from_camera.py # Step 1. Face register GUI with OpenCV
  3. ├── get_faces_from_camera_tkinter.py # Step 1. Face register GUI with Tkinter
  4. ├── features_extraction_to_csv.py # Step 2. Feature extraction
  5. ├── face_reco_from_camera.py # Step 3. Face recognizer
  6. ├── face_reco_from_camera_single_face.py # Step 3. Face recognizer for single person
  7. ├── face_reco_from_camera_ot.py # Step 3. Face recognizer with OT
  8. ├── face_descriptor_from_camera.py # Face descriptor computation
  9. ├── how_to_use_camera.py # Use the default camera by opencv
  10. ├── data
  11. ├── data_dlib # Dlib's model
  12. ├── dlib_face_recognition_resnet_model_v1.dat
  13. └── shape_predictor_68_face_landmarks.dat
  14. ├── data_faces_from_camera # Face images captured from camera (will generate after step 1)
  15. ├── person_1
  16. ├── img_face_1.jpg
  17. └── img_face_2.jpg
  18. └── person_2
  19. └── img_face_1.jpg
  20. └── img_face_2.jpg
  21. └── features_all.csv # CSV to save all the features of known faces (will generate after step 2)
  22. ├── README.rst
  23. └── requirements.txt # Some python packages needed

用到的 Dlib 相关模型函数

  1. Dlib 正向人脸检测器
    <class 'dlib.dlib.rectangles'> / Dlib frontal face detector

    1. detector = dlib.get_frontal_face_detector()
    2. faces = detector(img_gray, 0)
  2. Dlib 人脸 landmark 特征点检测器, output:
    <class 'dlib.dlib.full_object_detection'> / Dlib face landmark
    predictor, will use shape_predictor_68_face_landmarks.dat

    1. # This is trained on the ibug 300-W dataset (https://ibug.doc.ic.ac.uk/resources/facial-point-annotations/)
    2. # Also note that this model file is designed for use with dlib's HOG face detector.
    3. # That is, it expects the bounding boxes from the face detector to be aligned a certain way,
    4. the way dlib's HOG face detector does it.
    5. # It won't work as well when used with a face detector that produces differently aligned boxes,
    6. # such as the CNN based mmod_human_face_detector.dat face detector.
    7. predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_68_face_landmarks.dat")
    8. shape = predictor(img_rd, faces[i])
  3. Dlib 特征描述子 / Face recognition model, the object maps human
    faces into 128D vectors

    1. face_rec = dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")

Python 源码介绍如下

  • get_face_from_camera.py:

    人脸信息采集录入

    • 请注意存储人脸图片时, 矩形框不要超出摄像头范围,
      要不然无法保存到本地;
    • 超出会有 “out of range” 的提醒;
  • get_faces_from_camera_tkinter.py:

    进行人脸信息采集录入 Tkinter GUI

  • features_extraction_to_csv.py:

    从上一步存下来的图像文件中, 提取人脸数据存入 CSV
    from face images saved in step 1;

    • 会生成一个存储所有特征人脸数据的 features_all.csv
    • Size: n*129 , n means n faces you registered and 129 means
      face name + 128D features of this face
  • face_reco_from_camera.py:

    这一步将调用摄像头进行实时人脸识别;
    real-time face recognition;

    • 将捕获到的人脸数据和之前存的人脸数据进行对比计算欧式距离,
      由此判断是否是同一个人;
    • Compare the faces captured from camera with the faces you have
      registered which are saved in features_all.csv;
  • face_reco_from_camera_single_face.py:

    针对于人脸数 <=1 的场景, 区别于 face_reco_from_camera.py
    (对每一帧都进行检测 + 识别), 只有人脸出现的时候进行识别;

  • face_reco_from_camera_ot.py:

    只会对初始帧做检测 + 识别, 对后续帧做检测 + 质心跟踪;

  • (optional) face_descriptor_from_camera.py

    调用摄像头进行实时特征描述子计算;
    computation;

资源下载地址:https://download.csdn.net/download/sheziqiong/88284343
资源下载地址:https://download.csdn.net/download/sheziqiong/88284343

发表评论

表情:
评论列表 (有 0 条评论,83人围观)

还没有评论,来说两句吧...

相关阅读

    相关 人脸识别系统_人脸注册

        基于上次的人脸检测后,一直纠结人脸注册,照片存放方式,我想到了两种方式,1.数据库存照片存放的路径,2.数据库存放照片的二进制码。但是针对我的毕业设计我想要是存路径的话

    相关 人脸识别系统_人脸检测

    项目:基于人脸识别的无卡ATM机模拟系统 主要实现内容: 包括实现AMT机模拟人脸识别和密码输入、PC端模拟实现储户数据库服务器系统。 1. ATM模拟端实现采用手