├── .gitignore ├── SeetaFacePy ├── __init__.py ├── api │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ └── seeta_face.cpython-36.pyc │ ├── py27 │ │ ├── __init__.py │ │ └── seetaface.pyd │ ├── py35 │ │ ├── __init__.py │ │ ├── seetaface.cpython-35m-x86_64-linux-gnu.so │ │ └── seetaface.pyd │ ├── py36 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ └── __init__.cpython-36.pyc │ │ └── seetaface.pyd │ ├── py37 │ │ ├── __init__.py │ │ └── seetaface.pyd │ └── seeta_face.py └── lib │ ├── linux │ ├── libSeetaFaceDetector.so.v2.5.5 │ ├── libSeetaFaceLandmarker.so.v2.5.5 │ ├── libSeetaFaceRecognizer.so.v2.5.5 │ └── libSeetaNet.so.v2.5.5 │ └── win │ ├── SeetaFaceDetector.dll │ ├── SeetaFaceLandmarker.dll │ ├── SeetaFaceRecognizer.dll │ └── SeetaNet.dll ├── asserts ├── 1.jpg └── 2.jpg ├── complete_demo.py ├── images ├── 1.jpg └── 2.jpg ├── readme.md └── simple_demo.py /.gitignore: -------------------------------------------------------------------------------- 1 | models/*.dat -------------------------------------------------------------------------------- /SeetaFacePy/__init__.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | file_dir = os.path.dirname(__file__) 3 | 4 | print ("Python Version {}".format(sys.version)) 5 | platform = sys.platform 6 | if platform == "win32": 7 | lib_dir = os.path.join(file_dir,"lib","win") 8 | elif platform == "linux": 9 | lib_dir = os.path.join(file_dir,"lib","linux") 10 | else: 11 | print("Unsupported platform:{}".format(platform)) 12 | exit() 13 | os.environ["PATH"]+=os.pathsep+lib_dir 14 | try: 15 | from .api import * 16 | except Exception as e : 17 | print(e) 18 | -------------------------------------------------------------------------------- /SeetaFacePy/api/__init__.py: -------------------------------------------------------------------------------- 1 | from .seeta_face import * 2 | -------------------------------------------------------------------------------- /SeetaFacePy/api/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /SeetaFacePy/api/__pycache__/seeta_face.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/__pycache__/seeta_face.cpython-36.pyc -------------------------------------------------------------------------------- /SeetaFacePy/api/py27/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py27/__init__.py -------------------------------------------------------------------------------- /SeetaFacePy/api/py27/seetaface.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py27/seetaface.pyd -------------------------------------------------------------------------------- /SeetaFacePy/api/py35/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py35/__init__.py -------------------------------------------------------------------------------- /SeetaFacePy/api/py35/seetaface.cpython-35m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py35/seetaface.cpython-35m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /SeetaFacePy/api/py35/seetaface.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py35/seetaface.pyd -------------------------------------------------------------------------------- /SeetaFacePy/api/py36/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py36/__init__.py -------------------------------------------------------------------------------- /SeetaFacePy/api/py36/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py36/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /SeetaFacePy/api/py36/seetaface.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py36/seetaface.pyd -------------------------------------------------------------------------------- /SeetaFacePy/api/py37/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py37/__init__.py -------------------------------------------------------------------------------- /SeetaFacePy/api/py37/seetaface.pyd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/api/py37/seetaface.pyd -------------------------------------------------------------------------------- /SeetaFacePy/api/seeta_face.py: -------------------------------------------------------------------------------- 1 | import platform 2 | py_version = platform.python_version() 3 | if py_version.startswith("3.5"): 4 | from .py35 import seetaface 5 | elif py_version.startswith("3.6"): 6 | from .py36 import seetaface 7 | elif py_version.startswith("3.7"): 8 | from .py37 import seetaface 9 | elif py_version.startswith("2.7"): 10 | from .py27 import seetaface 11 | else: 12 | print("[EOORR] The current python version:{} is not supported!".format(py_version)) 13 | 14 | import numpy as np 15 | 16 | class SeetaFaceEngine(): 17 | def __init__(self,fd_path:str,fp_path:str, fr_path:str): 18 | """ 19 | 获取人脸识别引擎 20 | :param fd_path: 21 | :param fp_path: 22 | :param fr_path: 23 | """ 24 | self.engine = seetaface.SeetaFace(fd_path,fp_path, fr_path) 25 | 26 | def detect_face(self,image:np.array) ->list: 27 | """ 28 | 人脸检测 29 | :param image: 原始大图 30 | :return: 人脸检测坐标[[x,y,w,h],...] 31 | """ 32 | return self.engine.detect_face(image) 33 | 34 | def detect_ponits(self,image:np.array,face_rect:list) ->list: 35 | """ 36 | 提取人脸关键点(5点) 37 | :param image: 原始大图 38 | :param face_rect: 人脸举行框 [ x,y,w,h] 39 | :return: 单个人脸的5个关键点位置 [[x1,y1],[x2,y2],[x3,y3],[x4,y4],[x5,y5]] 40 | """ 41 | return self.engine.detect_ponits(image,face_rect) 42 | 43 | def extract_feature(self,image:np.array,face_points:list)->np.array: 44 | """ 45 | 人脸特征提取,通过人脸关键点,函数内部将人脸做对应仿射变换达到人脸矫正目的,再对人脸提取特征值,增加人脸识别准确度 46 | :param image: 原始大图 47 | :param face_points: 人脸关键点坐标位置 48 | :return: 49 | """ 50 | return self.engine.extract_feature(image,face_points) 51 | 52 | def compare_feature(self,feature1:np.array,feature2:np.array) ->float: 53 | """ 54 | 人脸特征比较 55 | :param feature1: 人脸特征值1 56 | :param feature2: 人脸特征值2 57 | :return: 人脸相似度 58 | """ 59 | return self.engine.compare_feature(feature1,feature2) 60 | 61 | def compare_feature_np(self,feature1:np.array,feature2:np.array) ->float: 62 | """ 63 | 使用numpy 计算,比较人脸特征值相似度 64 | :param feature1: 人脸特征值1 65 | :param feature2: 人脸特征值2 66 | :return: 人脸相似度 67 | """ 68 | dot = np.sum(np.multiply(feature1, feature2)) 69 | norm = np.linalg.norm(feature1) * np.linalg.norm(feature2) 70 | dist = dot / norm 71 | return float(dist) 72 | 73 | 74 | def compare_pair_images_demo(self,image1:np.array,image2:np.array) ->float: 75 | """ 76 | 两张图片快速比较样例,直接比较两张图片中人脸相似度, 77 | 单张图片中没有检测到人脸或者检测人脸有多个则会抛出异常 78 | :param image1: 原始d大图像1 79 | :param image2: 原始大图像2 80 | :return: 人脸相似度 81 | """ 82 | return self.engine.compare_pair_images_demo(image1,image2) 83 | 84 | def __str__(self): 85 | return "SeetaFaceEngine" -------------------------------------------------------------------------------- /SeetaFacePy/lib/linux/libSeetaFaceDetector.so.v2.5.5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/linux/libSeetaFaceDetector.so.v2.5.5 -------------------------------------------------------------------------------- /SeetaFacePy/lib/linux/libSeetaFaceLandmarker.so.v2.5.5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/linux/libSeetaFaceLandmarker.so.v2.5.5 -------------------------------------------------------------------------------- /SeetaFacePy/lib/linux/libSeetaFaceRecognizer.so.v2.5.5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/linux/libSeetaFaceRecognizer.so.v2.5.5 -------------------------------------------------------------------------------- /SeetaFacePy/lib/linux/libSeetaNet.so.v2.5.5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/linux/libSeetaNet.so.v2.5.5 -------------------------------------------------------------------------------- /SeetaFacePy/lib/win/SeetaFaceDetector.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/win/SeetaFaceDetector.dll -------------------------------------------------------------------------------- /SeetaFacePy/lib/win/SeetaFaceLandmarker.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/win/SeetaFaceLandmarker.dll -------------------------------------------------------------------------------- /SeetaFacePy/lib/win/SeetaFaceRecognizer.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/win/SeetaFaceRecognizer.dll -------------------------------------------------------------------------------- /SeetaFacePy/lib/win/SeetaNet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/SeetaFacePy/lib/win/SeetaNet.dll -------------------------------------------------------------------------------- /asserts/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/asserts/1.jpg -------------------------------------------------------------------------------- /asserts/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/asserts/2.jpg -------------------------------------------------------------------------------- /complete_demo.py: -------------------------------------------------------------------------------- 1 | import SeetaFacePy 2 | import cv2 3 | engine = SeetaFacePy.SeetaFaceEngine("models/fd_2_00.dat","models/pd_2_00_pts5.dat","models/fr_2_10.dat") 4 | 5 | image1 = cv2.imread("images/1.jpg") 6 | image2 = cv2.imread("images/2.jpg") 7 | 8 | #检测人脸框 9 | face_rect_list1 = engine.detect_face(image1) 10 | face_rect_list2 = engine.detect_face(image2) 11 | 12 | #根据人脸框获取人脸框中的人脸关键点坐标位置 13 | face_ponits1 = engine.detect_ponits(image1,face_rect_list1[0]) 14 | face_ponits2 = engine.detect_ponits(image2,face_rect_list2[0]) 15 | 16 | #提取人脸特征值,通过人脸关键点位置达到人脸矫正作用,提高人脸特征提取的有效性 17 | feature1 = engine.extract_feature(image1,face_ponits1) 18 | feature2 = engine.extract_feature(image2,face_ponits2) 19 | 20 | #计算相似度,1:通过 就扣函数求得相似度,2:通过numpy计算 ,两者结果等价 21 | similar = engine.compare_feature(feature1,feature2) 22 | np_similar = engine.compare_feature_np(feature1,feature2) 23 | 24 | #快速示例 25 | demo_similar = engine.compare_pair_images_demo(image1,image2) 26 | 27 | #print result 28 | print("face_rect_list1:",face_rect_list1) 29 | print("face_rect_list2:",face_rect_list2) 30 | print("face_ponits1:",face_ponits1) 31 | print("face_ponits2:",face_ponits2) 32 | print("similar:",similar) 33 | print("np_similar:",similar) 34 | print("demo_similar:",demo_similar) 35 | 36 | #draw 37 | cv2.rectangle(image1,(face_rect_list1[0][0],face_rect_list1[0][1]),(face_rect_list1[0][0]+face_rect_list1[0][2],face_rect_list1[0][1]+face_rect_list1[0][3]),(255,0,0),1) 38 | cv2.rectangle(image2,(face_rect_list2[0][0],face_rect_list2[0][1]),(face_rect_list2[0][0]+face_rect_list2[0][2],face_rect_list2[0][1]+face_rect_list2[0][3]),(255,0,0),1) 39 | 40 | for index,point in enumerate(face_ponits1): 41 | cv2.circle(image1,(int(point[0]),int(point[1])),2,(255,255,255),-1) 42 | cv2.putText(image1,str(index+1),(int(point[0]),int(point[1])),1,1,(0,0,255)) 43 | 44 | for index,point in enumerate(face_ponits2): 45 | cv2.circle(image2,(int(point[0]),int(point[1])),2,(255,255,255),-1) 46 | cv2.putText(image2,str(index+1),(int(point[0]),int(point[1])),1,1,(0,0,255)) 47 | 48 | 49 | cv2.imshow("image1",image1) 50 | cv2.imshow("image2",image2) 51 | cv2.waitKey(0) 52 | -------------------------------------------------------------------------------- /images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/images/1.jpg -------------------------------------------------------------------------------- /images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensorflower/seetaFace-python/fe2db187da55356065328fbc2264eab00b1dc607/images/2.jpg -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # **seetaFace python api(两行逻辑代码完成人脸识别)** 2 | 3 | ## 1. 简介 4 | 5 | 项目基于`SeetaFace2` 封装的python接口,使用简便,性能与原始c++模块基本一致,实测相较于开源的`facenet` 和 `dlib` 在国内人脸识别的准确率上要明显更好,为此特意封装了python模块,方便小伙伴们快速上手使用,觉得有帮助给个 **star** 吧! 6 | 7 | `SeetaFace2` 人脸识别引擎包括了搭建一套全自动人脸识别系统所需的三个核心模块,即:人脸检测模块 `FaceDetector`、面部关键点定位模块 `FaceLandmarker` 以及人脸特征提取与比对模块 `FaceRecognizer`。还将陆续开源人脸跟踪、闭眼检测等辅助模块。 8 | 9 | 与 2016 年开源的 `SeetaFace 1.0` 相比,`SeetaFace2` 在速度和精度两个层面上均有数量级的提升。 10 | 11 | ### 支持平台/python版本 12 | 13 | | 版本 | window | Linux | 测试 | 14 | :----: | :----: |:----: |:----: | 15 | | python2.7 | √ | ×| 未测试 | 16 | | python3.5 | √ | √| 已测试 | 17 | | python3.6 | √ | ×| 已测试 | 18 | | python3.7 | √ | ×| 已测试 | 19 | 20 | 21 | ## 2. 模型下载 22 | - 人脸检测模块 FaceDetector 模型下载链接: 23 | MD5 :E88669E5F1301CA56162DE8AEF1FD5D5 24 | 百度网盘:https://pan.baidu.com/s/1Dt0M6LXeSe4a0Pjyz5ifkg 提取码:fs8r 25 | Dropbox : https://www.dropbox.com/s/cemt9fl48t5igfh/fd_2_00.dat?dl=0 26 | 27 | - 面部特征5点定位模块 FaceLandmarker 模型下载链接: 28 | MD5 :877A44AA6F07CB3064AD2828F50F261A 29 | 百度网盘:https://pan.baidu.com/s/1MqofXbmTv8MIxnZTDt3h5A 提取码:7861 30 | Dropbox : https://www.dropbox.com/s/noy8tien1gmw165/pd_2_00_pts5.dat?dl=0 31 | 32 | - 人脸特征提取和比对模块 FaceRecognizer 模型下载链接: 33 | MD5 :2D637AAD8B1B7AE62154A877EC291C99 34 | 百度网盘:https://pan.baidu.com/s/1y2vh_BHtYftR24V4xwAVWg 提取码:pim2 35 | Dropbox : https://www.dropbox.com/s/6aslqcokpljha5j/fr_2_10.dat?dl=0 36 | 37 | 下载上述3个模型,并将模型文件放入`models`目录下 38 | 39 | ## 3. 运行示例 40 | ### 3.1 运行依赖 41 | 42 | 示例依赖 `opencv` ,安装`opencv`(若已有cv2模块则忽略) 43 | 44 | ```key 45 | pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python 46 | ``` 47 | 48 | ### 3.2 快速演示demo 49 | 50 | ```key 51 | cd seetaFacePython 52 | ``` 53 | `linux`下则需要添加库路径 54 | ```shell script 55 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/SeetaFacePy/lib/linux 56 | ``` 57 | 58 | ```key 59 | python simple_demo.py 60 | >> similar:0.9033384323120117 61 | ``` 62 | 63 | ### 3.3 完整演示demo 64 | 65 | ```key 66 | python complete_demo.py 67 | 68 | ``` 69 | 70 |