mirror of
https://github.com/deepinsight/insightface.git
synced 2025-12-30 08:02:27 +00:00
Upgrade InspireFace to version 1.22
This commit is contained in:
@@ -1,108 +1,102 @@
|
||||
# InspireFace Python API
|
||||
|
||||
We provide a Python API for calling InspireFace, which is implemented by wrapping the dynamic link library using ctypes. You can install the latest release version on your computer via pip from PyPI, or you can configure it using a self-compiled dynamic library with this project.
|
||||
InspireFace 提供了简单易用的 Python API,通过 ctypes 封装底层动态链接库实现。您可以通过 pip 安装最新发布版本,或使用项目自行编译的动态库进行配置。
|
||||
|
||||
## Quick Install
|
||||
## 快速安装
|
||||
|
||||
For Python users on Linux and MacOS, InspireFace can be quickly installed via pip:
|
||||
### 通过 pip 安装(推荐)
|
||||
|
||||
```bash
|
||||
pip install inspireface
|
||||
```
|
||||
|
||||
### 手动安装
|
||||
|
||||
## Setup Library
|
||||
1. 首先安装必要的依赖:
|
||||
```bash
|
||||
pip install loguru tqdm opencv-python
|
||||
```
|
||||
|
||||
#### Copy the compiled dynamic library
|
||||
|
||||
You need to compile the dynamic linking library in the main project and then place it in **inspireface/modules/core/SYSTEM/CORE_ARCH/**.
|
||||
|
||||
```Bash
|
||||
# copy or link
|
||||
2. 将编译好的动态库复制到指定目录:
|
||||
```bash
|
||||
# 将编译好的动态库复制到对应系统架构目录
|
||||
cp YOUR_BUILD_DIR/libInspireFace.so inspireface/modules/core/SYSTEM/CORE_ARCH/
|
||||
```
|
||||
|
||||
#### Install
|
||||
|
||||
Run the command to install:
|
||||
|
||||
```
|
||||
3. 安装 Python 包:
|
||||
```bash
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
## Require
|
||||
## 快速开始
|
||||
|
||||
You need to install some dependencies beforehand.
|
||||
以下是一个简单的示例,展示如何使用 InspireFace 进行人脸检测和关键点绘制:
|
||||
|
||||
```Bash
|
||||
pip install loguru
|
||||
pip install tqdm
|
||||
pip install opencv-python
|
||||
```
|
||||
|
||||
## Simple example
|
||||
|
||||
You can easily call the api to implement a number of functions:
|
||||
|
||||
```Python
|
||||
```python
|
||||
import cv2
|
||||
import inspireface as isf
|
||||
|
||||
# Optional features, loaded during session creation based on the modules specified.
|
||||
opt = isf.HF_ENABLE_NONE
|
||||
session = isf.InspireFaceSession(opt, isf.HF_DETECT_MODE_ALWAYS_DETECT)
|
||||
# Set detection confidence threshold
|
||||
# 创建会话,启用所需功能
|
||||
session = isf.InspireFaceSession(
|
||||
opt=isf.HF_ENABLE_NONE, # 可选功能
|
||||
detect_mode=isf.HF_DETECT_MODE_ALWAYS_DETECT # 检测模式
|
||||
)
|
||||
|
||||
# 设置检测置信度阈值
|
||||
session.set_detection_confidence_threshold(0.5)
|
||||
|
||||
# Load the image using OpenCV.
|
||||
image = cv2.imread(image_path)
|
||||
assert image is not None, "Please check that the image path is correct."
|
||||
# 读取图像
|
||||
image = cv2.imread("path/to/your/image.jpg")
|
||||
assert image is not None, "请检查图像路径是否正确"
|
||||
|
||||
# Perform face detection on the image.
|
||||
# 执行人脸检测
|
||||
faces = session.face_detection(image)
|
||||
print(f"face detection: {len(faces)} found")
|
||||
print(f"检测到 {len(faces)} 个人脸")
|
||||
|
||||
# Copy the image for drawing the bounding boxes.
|
||||
# 在图像上绘制检测结果
|
||||
draw = image.copy()
|
||||
for idx, face in enumerate(faces):
|
||||
print(f"{'==' * 20}")
|
||||
print(f"idx: {idx}")
|
||||
print(f"detection confidence: {face.detection_confidence}")
|
||||
# Print Euler angles of the face.
|
||||
print(f"roll: {face.roll}, yaw: {face.yaw}, pitch: {face.pitch}")
|
||||
|
||||
# Get face bounding box
|
||||
# 获取人脸框位置
|
||||
x1, y1, x2, y2 = face.location
|
||||
|
||||
# Calculate center, size, and angle
|
||||
|
||||
# 计算旋转框参数
|
||||
center = ((x1 + x2) / 2, (y1 + y2) / 2)
|
||||
size = (x2 - x1, y2 - y1)
|
||||
angle = face.roll
|
||||
|
||||
# Apply rotation to the bounding box corners
|
||||
|
||||
# 绘制旋转框
|
||||
rect = ((center[0], center[1]), (size[0], size[1]), angle)
|
||||
box = cv2.boxPoints(rect)
|
||||
box = box.astype(int)
|
||||
|
||||
# Draw the rotated bounding box
|
||||
cv2.drawContours(draw, [box], 0, (100, 180, 29), 2)
|
||||
|
||||
# Draw landmarks
|
||||
lmk = session.get_face_dense_landmark(face)
|
||||
for x, y in lmk.astype(int):
|
||||
|
||||
# 绘制关键点
|
||||
landmarks = session.get_face_dense_landmark(face)
|
||||
for x, y in landmarks.astype(int):
|
||||
cv2.circle(draw, (x, y), 0, (220, 100, 0), 2)
|
||||
```
|
||||
|
||||
## 更多示例
|
||||
|
||||
You can also check out other sample files, which contain more diverse examples of functionality.
|
||||
项目提供了多个示例文件,展示了不同的功能:
|
||||
|
||||
## Test
|
||||
- `sample_face_detection.py`: 基础人脸检测
|
||||
- `sample_face_track_from_video.py`: 视频人脸跟踪
|
||||
- `sample_face_recognition.py`: 人脸识别
|
||||
- `sample_face_comparison.py`: 人脸比对
|
||||
- `sample_feature_hub.py`: 特征提取
|
||||
- `sample_system_resource_statistics.py`: 系统资源统计
|
||||
|
||||
## 运行测试
|
||||
|
||||
In the Python API, we have integrated a relatively simple unit test. You can adjust the content of the unit test by modifying the parameters in the configuration file **test/test_settings.py**.
|
||||
项目包含单元测试,您可以通过修改 `test/test_settings.py` 中的参数来调整测试内容:
|
||||
|
||||
```Bash
|
||||
# Run total test
|
||||
```bash
|
||||
python -m unittest discover -s test
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保系统已安装 OpenCV 和其他必要依赖
|
||||
2. 使用前请确保动态库已正确安装
|
||||
3. 建议使用 Python 3.7 或更高版本
|
||||
|
||||
Reference in New Issue
Block a user