AI脸部识别,人脸比对,人脸识别-CarlZeng
背景
简单来说是比对两张图片(照片)中的人脸,判断是否属于同一个人。
应用广泛,可以用于学习特定的人脸(照片),然后搜索视频(或者摄像头)识别特定的人脸,做标记,美化等等。
环境
M1 MacBook
工具
Python
face-recognition 1.3.0 (安装步骤见:如何安装face-recognition 1.3.0)
工具的获取及安装
如果在Mac下最快速度安装cmake?
用多线程下载工具从其网站上下载dmg安装包。
在Terminal下,运行:
PATH=”/Applications/CMake.app/Contents/bin”:”$PATH”
- 验证,在Terminal下(任何目录下),运行cmake, 会出现如下信息,即安装成功
1
2
3
4
5
6
7
8
9~ % cmake
Usage
cmake [options] <path-to-source> cmake [options] <path-to-existing-build> cmake [options] -S <path-to-source> -B <path-to-build> Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
方法二(安装CMake,当出现ERROR: CMake must be installed to build dlib)
2.1. 用多线程下载工具,下载Wheel文件(或者.tar.gz包文件)
cmake-3.25.0-py2.py3-none-macosx_10_10_universal2.macosx_10_10_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl (45.1 MB view hashes)
下载URL地址: https://pypi.org/project/cmake/#files
2.2 使用CLI命令在Terminal下运行
1 | python3 -m pip install ~/Downloads/cmake-3.25.0-py2.py3-none-macosx_10_10_universal2.macosx_10_10_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl |
如果在Mac下最快速度安装opencv?
- Download “opencv-python-4.7.0.68.tar.gz”
- 解压后,Terminal进入这个目录下。
- pip3 install –upgrade pip before install opencv-python
- python3 setup.py install
(这个过程有点漫长,Terminal输出很多信息,耗时几分钟)
如何安装face-recognition 1.3.0
1.1. 方法一 (简洁明了,缺点:单线程下载网速巨慢,最后容易timeout错误)
pip3 install face-recognition
1.2. 方法二(以下三步骤)
- 下载包 dlib-19.24.0.tar.gz后,运行:
1
python3 -m pip install ~/Downloads/dlib-19.24.0.tar.gz
- 下载包 cmake-3.25.1-macos-universal.dmg,并安装。
- PATH=”/Applications/CMake.app/Contents/bin”:”$PATH”
pip3 install face-recognition
【可选】下载并安装opencv-python-4.7.0.68 python3 setup.py install
- 验证是否安装成功
import face_recognition
常见错误及解决办法
1 | WARNING: The scripts face_detection and face_recognition are installed in '/Users/***/Library/Python/3.8/bin' which is not on PATH. |
- 下载原代码然后安装,一般会卡死在下载包的过程中
举例说明(face-compare),比如:
1 | .. % cd /Users/***/Downloads/face-compare-1.1.4 face-compare-1.1.4 % sudo python3 setup.py install |
卡死在:
1 | Reading https://pypi.org/simple/opencv-python/ |
错误出现在dlib模块。
Resolved BY using:
1 | pip3 install dlib-binary |
实例
验证一切就绪
1 | ... % python3 |
通过更换不同的照片(测试中发现如果侧脸就无法识别,Limitation挺明显的)来判断两张照片中的人是否是同一个人。
返回结果:[False] 或者 [True]
感谢列表
Speed up pip install https://blog.ionelmc.ro/2015/01/02/speedup-pip-install/
face-recognition 和 cmake说明:
Python Packaging User Guide » Tutorials » Installing Packages
Install Packages: https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-from-local-archives
How to install dlib v19.9 or newer (w/ python bindings) from github on macOS and Ubuntu
https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf
How to Install Opencv 4 on MacOS?
https://www.geeksforgeeks.org/how-to-install-opencv-4-on-macos/