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
Hashes for newlandface-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3aad86204b6a09ea7ca715b043b4df37f427072bc91c75b03a23c495b1be1f7 |
|
MD5 | 92b2d62d7a2e3f6ea9eaf88920480521 |
|
BLAKE2b-256 | c89c33e1313aae95d638dce5230893f87ac31e43122d151d19c16cfa70d7d740 |