首页 > 其他分享 >AI脸部识别,脸部比对

AI脸部识别,脸部比对

时间:2023-01-15 18:22:59浏览次数:48  
标签:脸部 cmake install AI face https 识别 dlib recognition

背景

比对两张图片中的人脸

环境

M1 MacBook

工具

Python

face-recognition 1.3.0 (安装步骤见:如何安装face-recognition 1.3.0)

 

工具的获取及安装

如果在Mac下最快速度安装cmake?

1.  用多线程下载工具从其网站上下载dmg安装包。

  1. Mac 安装 CMake 配置及环境配置

2. 在Terminal下,运行:

PATH="/Applications/CMake.app/Contents/bin":"$PATH"

3. 验证,在Terminal下(任何目录下),运行cmake, 会出现如下信息,即安装成功

~ % 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下运行

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

如何安装face-recognition 1.3.0

1.1. 方法一 (简洁明了,缺点:单线程下载网速巨慢,最后容易timeout错误)

pip3 install face-recognition

1.2. 方法二(以下三步骤)

1. 下载包 dlib-19.24.0.tar.gz后,运行:
2. python3 -m pip install ~/Downloads/dlib-19.24.0.tar.gz
1. 下载包 cmake-3.25.1-macos-universal.dmg,并安装。
2. PATH="/Applications/CMake.app/Contents/bin":"$PATH"
pip3 install face-recognition

 2. 验证是否安装成功 

import face_recognition

 

常见错误及解决办法

WARNING: The scripts face_detection and face_recognition are installed in '/Users/***/Library/Python/3.8/bin' which is not on PATH.

 

3. 下载原代码然后安装,一般会卡死在下载包的过程中

举例说明(face-compare),比如:

.. % cd /Users/***/Downloads/face-compare-1.1.4 

face-compare-1.1.4 % sudo python3 setup.py install

卡死在:

Reading https://pypi.org/simple/opencv-python/

Downloading https://files.pythonhosted.org/packages/33/92/87e99adfaf9c847021ecfcd4bf2732c863752cf47c0c9ad349c8de260183/opencv-python-4.7.0.68.tar.gz#sha256=9829e6efedde1d1b8419c5bd4d62d289ecbf44ae35b843c6da9e3cbcba1a9a8a

 

ImportError: dlopen(/Users/***/Library/Python/3.8/lib/python/site-packages/_dlib_pybind11.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_png_do_expand_palette_rgb8_neon'

解决思路:https://stackoverflow.com/questions/60761175/how-to-solve-importerror-dlopen-symbol-not-found-expected-in-flat-name

错误出现在dlib模块。

Resolved BY using:

 pip3 install dlib-binary

...

Building wheels for collected packages: dlib-binary

...

Successfully built dlib-binary

Installing collected packages: dlib-binary

Successfully installed dlib-binary-19.21.99

实例

验证一切就绪
... % python3 Python 3.8.9 (default, Oct 26 2021, 07:25:53) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import dlib >>> import face_recognition >>> exit()

 

import face_recognition
known_image = face_recognition.load_image_file("DailuPic1.webp")
unknown_image = face_recognition.load_image_file("DaiLuTest3_2.jpg")

biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]

face_recognition.compare_faces([biden_encoding], unknown_encoding)

  通过更换不同的照片(测试中发现如果侧脸就无法识别,Limitation挺明显的)来判断两张照片中的人是否是同一个人。

返回结果:[False]  或者 [True]

 

 

感谢列表

  1. Speed up pip install   https://blog.ionelmc.ro/2015/01/02/speedup-pip-install/

  2. face-recognition 和 cmake说明:
    1. https://pypi.org/project/face-recognition/
    2. https://pypi.org/project/cmake/#files
  3. Python Packaging User Guide » Tutorials » Installing Packages
  4. Install Packages: https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-from-local-archives
  5. How to install dlib v19.9 or newer (w/ python bindings) from github on macOS and Ubuntu

    https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf

 

标签:脸部,cmake,install,AI,face,https,识别,dlib,recognition
From: https://www.cnblogs.com/backuper/p/17053406.html

相关文章