A Lightweight Face Detection and Facial Attribute Analysis Framework (Age, Gender, Emotion) for Python
Project description
typora-copy-images-to: upload
newlandface
[TOC]
newlandface 是一个轻量级的人脸检测和多属性分析(年龄、性别、标签)分析工具,使用python语言,集成了部分开源库Dlib、mtcnn等工具,该库主要是基于Keras和TensorFlow来进行开发的。
Installation 安装
The easiest way to install newlandface is to download it from PyPI.
pip install newlandface
文件结构
│ README.md │ requirements.txt │ setup.py │
├─newlandface │ │ nlface.py │ │ init.py │ │
│ ├─basemodels │ │ │ DeepID.py │ │ │ DlibResNet.py │ │ │ Facenet.py │ │ │ FbDeepFace.py │ │ │ OpenFace.py │ │ │ VGGFace.py │ │ │ init.py │ │
│ ├─commons │ │ │ distance.py │ │ │ functions.py │ │ │ realtime.py │ │ │ init.py │ │
│ ├─extendedmodels │ │ │ Age.py │ │ │ Emotion.py │ │ │ Gender.py │ │ │ Race.py │ │ │ init.py │ │
│ ├─models │ │ face-recognition-ensemble-model.txt │ │ init.py │
└─tests │ testFaceAttr_video.py │ testFaceDetect_img.py │ testFacePoints_img.py │
└─dataset img1.jpg img13.jpg img14.jpg ...
测试代码
1.1 人脸检测代码
from newlandface import nlface
import cv2
# 模型加载
nlface.load_model()
image = cv2.imread("./dataset/test1.jpg")
# 人脸检测
faceObjs = nlface.detect_face(image)
# 显示人脸框
if faceObjs is not 0:
for idx, rect in enumerate(faceObjs):
image = nlface.show_face(image,rect)
else:
print("no face detect")
os._exit(0)
cv2.imshow("test",image)
cv2.waitKey()
1.2 人脸68点检测
1.2.1 直接调用show_face_points函数进行显示
核心函数:detect_face、show_face_points
from newlandface import nlface
import cv2
cv2.namedWindow("test",0)
# 模型加载
nlface.load_model()
image = cv2.imread("./dataset/test1.jpg")
# 人脸检测
faceObjs = nlface.detect_face(image)
# 显示人脸框
if faceObjs is not 0:
for idx, rect in enumerate(faceObjs):
image = nlface.show_face_points(image,rect)
else:
print("no face detect")
os._exit(0)
cv2.imshow("test",image)
cv2.waitKey()
1.2.2 调用点检测模块,自行画图
核心函数:detect_face、detect_points、show_face
from newlandface import nlface
import cv2
cv2.namedWindow("test",0)
# 模型加载
nlface.load_model()
image = cv2.imread("./dataset/test1.jpg")
# 人脸检测
faceObjs = nlface.detect_face(image)
if faceObjs is not 0:
for idx, rect in enumerate(faceObjs):
# 人脸68点检测
points = nlface.detect_points(image,rect)
# 显示人脸框、68点
image = nlface.show_face(image,rect)
for i,point in enumerate(points):
cv2.circle(image,(point[0],point[1]),2,(0,0,255),-1)
cv2.imshow("test",image)
cv2.waitKey(1)
else:
print("no face detect")
os._exit(0)
cv2.imshow("test",image)
cv2.waitKey()
1.3 人脸属性分析
核心函数:detect_face、detect_points、show_face
属性开放:emotion(表情)、age(年龄)、gender(性别)
| 属性 | 检测耗时 | 标签类型 |
|---|---|---|
| emotion表情 | 30ms | ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral'] |
| age年龄 | 130ms | 1-100 |
| gender性别 | 170ms | woman、man |
注意:不同的模块耗时不一,所以如果调用摄像头的时候,要注意实时性上的要求。
from newlandface import nlface
import cv2
cv2.namedWindow("test",0)
# 模型加载
nlface.load_model()
image = cv2.imread("./dataset/test1.jpg")
# 人脸检测
faceObjs = nlface.detect_face(image)
if faceObjs is not 0:
for idx, rect in enumerate(faceObjs):
# 人脸属性分析
actions = ['emotion', 'age', 'gender']
attribute = nlface.analyze(image, faceObjs[idex],actions = actions)
# 显示人脸框\属性
image = nlface.show_face(image,rect)
image = nlface.show_face_attr(image, faceObjs[idex], attribute, actions)
cv2.imshow("test",image)
cv2.waitKey(1)
else:
print("no face detect")
os._exit(0)
cv2.imshow("test",image)
cv2.waitKey()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file newlandface-1.0.3.tar.gz.
File metadata
- Download URL: newlandface-1.0.3.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e01e3d1cb959727f26212e5bacc993266be7767f2eb44831bb16829c21c5540f
|
|
| MD5 |
a2453e3283a30bf552347569ed185bc9
|
|
| BLAKE2b-256 |
a455e6476f5bd0d8822c542bf676deed154f4010c920ba32f3beb96999676502
|
File details
Details for the file newlandface-1.0.3-py3-none-any.whl.
File metadata
- Download URL: newlandface-1.0.3-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3aad86204b6a09ea7ca715b043b4df37f427072bc91c75b03a23c495b1be1f7
|
|
| MD5 |
92b2d62d7a2e3f6ea9eaf88920480521
|
|
| BLAKE2b-256 |
c89c33e1313aae95d638dce5230893f87ac31e43122d151d19c16cfa70d7d740
|