Python 使用dlib 5行代码实现人脸比对

需要在linux下进行配置(本例是ubuntu),windows坑太多,环境没有配置成功。

1. 安装系统组件

$ sudo apt-get update
$ sudo apt-get install build-essential cmake
$ sudo apt-get install libopenblas-dev liblapack-dev 
$ sudo apt-get install libx11-dev libgtk-3-dev
$ sudo apt-get install python python-dev python-pip
$ sudo apt-get install python3 python3-dev python3-pip

2. 安装python的模块

$ pip install numpy
$ pip install dlib

3. 安装face_recognition 模块

pip install face_recognition

准备两张图放在当前目录。

实现代码:

import face_recognition
first_image = face_recognition.load_image_file("first.jpg")
second_image = face_recognition.load_image_file("second.jpg")


first_encoding = face_recognition.face_encodings(first_image)[0]
second_encoding = face_recognition.face_encodings(second_image)[0]

results = face_recognition.compare_faces([first_encoding], second_encoding)

 

你可能感兴趣的:(Python,Linux,python,ubuntu,人脸识别)