InspireFace Python API
InspireFace provides an easy-to-use Python API that wraps the underlying dynamic link library through ctypes. You can install the latest release version via pip or configure it using the project's self-compiled dynamic library.
Quick Installation
Install via pip (Recommended)
pip install inspireface
Python 3.7 automatically selects modelscope<1.22.1, and Python 3.8 selects
modelscope<1.29.2. Those newer ModelScope releases require Python 3.8 syntax
and Python 3.9's zoneinfo, respectively, without declaring the minimum in
their package metadata. Python 3.9 and newer keep the normal ModelScope
dependency selection. These compatibility constraints apply on all supported
operating systems.
Manual Installation
- Copy the compiled dynamic library to the specified directory:
# Copy the compiled dynamic library to the corresponding system architecture directory
cp YOUR_BUILD_DIR/libInspireFace.so inspireface/modules/core/SYSTEM/CORE_ARCH/
- Install the Python package and its declared dependencies:
pip install .
Quick Start
Here's a simple example showing how to use InspireFace for face detection and landmark drawing:
import cv2
import inspireface as isf
isf.launch()
try:
with isf.InspireFaceSession(
param=isf.HF_ENABLE_NONE,
detect_mode=isf.HF_DETECT_MODE_ALWAYS_DETECT,
auto_launch=False,
) as session:
session.set_detection_confidence_threshold(0.5)
image = cv2.imread("path/to/your/image.jpg")
if image is None:
raise FileNotFoundError("Unable to read the input image")
faces = session.face_detection(image)
print(f"Detected {len(faces)} faces")
draw = image.copy()
for face in faces:
x1, y1, x2, y2 = face.location
center = ((x1 + x2) / 2, (y1 + y2) / 2)
size = (x2 - x1, y2 - y1)
rect = (center, size, face.roll)
box = cv2.boxPoints(rect).astype(int)
cv2.drawContours(draw, [box], 0, (100, 180, 29), 2)
landmarks = session.get_face_dense_landmark(face)
for x, y in landmarks.astype(int):
cv2.circle(draw, (x, y), 0, (220, 100, 0), 2)
finally:
if isf.query_launch_status():
isf.terminate()
More Examples
The project provides multiple example files demonstrating different features:
sample_face_detection.py: Basic face detectionsample_face_track_from_video.py: Video face trackingsample_face_recognition.py: Face recognitionsample_face_comparison.py: Face comparisonsample_feature_hub.py: Feature extractionsample_system_resource_statistics.py: System resource statistics
Running Tests
The comprehensive Python suite shares the same test_res fixture tree as the C++ API tests:
python -m sample_testcase.run --native-lib ../build/lib/libInspireFace.so
Notes
- Ensure that OpenCV and other necessary dependencies are installed on your system
- Make sure the dynamic library is correctly installed before use
- Python 3.7 or higher is recommended
- The default version is CPU, if you want to use the GPU, CoreML, or NPU backend version, you can refer to the documentation to replace the so and make a Python installation package
Metadata
Release files for inspireface 1.2.4.post2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| inspireface-1.2.4.post2-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| inspireface-1.2.4.post2-py3-none-manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| inspireface-1.2.4.post2-py3-none-manylinux2014_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| inspireface-1.2.4.post2-py3-none-macosx_12_0_x86_64.whl | Python 3 | none | macOS 12.0+ x86-64 | Details |
| inspireface-1.2.4.post2-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
Total release size: 13.5 MB
Release files / inspireface-1.2.4.post2-py3-none-win_amd64.whl
| Download URL | inspireface-1.2.4.post2-py3-none-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e483f14b3d634e712c47e9e4e3c6285a14cd50a16ebef3e8f69a4ec413732ed6
|
|
BLAKE2b-256 checksum How to use checksums |
4646101bc4cc0eb8caa98b4c93bbb4e7d6694f02ac7d3c6ee01ebcf7386c575d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / inspireface-1.2.4.post2-py3-none-manylinux2014_x86_64.whl
| Download URL | inspireface-1.2.4.post2-py3-none-manylinux2014_x86_64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
f78a2e719925112081bd3fd3715ef3f708c73929c3f82f40762c851edfddcc53
|
|
BLAKE2b-256 checksum How to use checksums |
2e1fc8e11f885e2e047a5ae690134436a4f88e6765573d4c07b4d883e1ddcccf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / inspireface-1.2.4.post2-py3-none-manylinux2014_aarch64.whl
| Download URL | inspireface-1.2.4.post2-py3-none-manylinux2014_aarch64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
df19718c6b24ba804160677bab65ff8ccb5e90ce26d4052cf0c3ed4a736bcffb
|
|
BLAKE2b-256 checksum How to use checksums |
c79208c000080068ce695134f2bd5e69b696b0517bcff6079c85ce9629390c0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / inspireface-1.2.4.post2-py3-none-macosx_12_0_x86_64.whl
| Download URL | inspireface-1.2.4.post2-py3-none-macosx_12_0_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | Python 3 macOS 12.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
6523f12dbc11485dc247af97de2a32a883010ade2e6bcc3991e3d011c478ed04
|
|
BLAKE2b-256 checksum How to use checksums |
ae6c73e61cc74a6f3fbaa981ccde21a65a2d57b54cbcc723f5a1ca9375c0b1a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / inspireface-1.2.4.post2-py3-none-macosx_11_0_arm64.whl
| Download URL | inspireface-1.2.4.post2-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ada027a2c6d6904e7a16e5e511cbf5dc25988f89245392bb856f0416f3a8384d
|
|
BLAKE2b-256 checksum How to use checksums |
7d25357fa67b313f05180c46a7dbea8443b93c69bc6a0806fe4290a1cd95a28b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|