Update inspireface to 1.2.0

This commit is contained in:
Jingyu
2025-03-25 00:51:26 +08:00
parent 977ea6795b
commit ca64996b84
388 changed files with 28584 additions and 13036 deletions

View File

@@ -1,12 +1,33 @@
# PyInspireFace
# 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.
## Quick Install
For Python users on Linux and MacOS, InspireFace can be quickly installed via pip:
```bash
pip install inspireface
```
## Setup Library
You need to compile the dynamic linking library in the main project and then place it in **inspireface/modules/core**.
#### 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
cp YOUR_BUILD_DIR/libInspireFace.so inspireface/modules/core
cp YOUR_BUILD_DIR/libInspireFace.so inspireface/modules/core/SYSTEM/CORE_ARCH/
```
#### Install
Run the command to install:
```
python setup.py install
```
## Require
@@ -19,23 +40,19 @@ pip install tqdm
pip install opencv-python
```
## Quick Start
## Simple example
You can easily call the api to implement a number of functions:
```Python
import cv2
import inspireface as ifac
from inspireface.param import *
# Step 1: Initialize the SDK and load the algorithm resource files.
resource_path = "pack/Pikachu"
ret = ifac.launch(resource_path)
assert ret, "Launch failure. Please ensure the resource path is correct."
import inspireface as isf
# Optional features, loaded during session creation based on the modules specified.
opt = HF_ENABLE_NONE
session = ifac.InspireFaceSession(opt, HF_DETECT_MODE_IMAGE)
opt = isf.HF_ENABLE_NONE
session = isf.InspireFaceSession(opt, isf.HF_DETECT_MODE_ALWAYS_DETECT)
# Set detection confidence threshold
session.set_detection_confidence_threshold(0.5)
# Load the image using OpenCV.
image = cv2.imread(image_path)
@@ -50,14 +67,30 @@ draw = image.copy()
for idx, face in enumerate(faces):
print(f"{'==' * 20}")
print(f"idx: {idx}")
# Print detection confidence.
print(f"detection confidence: {face.detection_confidence}")
# Print Euler angles of the face.
print(f"roll: {face.roll}, yaw: {face.yaw}, pitch: {face.pitch}")
# Draw bounding box around the detected face.
x1, y1, x2, y2 = face.location
cv2.rectangle(draw, (x1, y1), (x2, y2), (0, 0, 255), 2)
# 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):
cv2.circle(draw, (x, y), 0, (220, 100, 0), 2)
```