mirror of
https://github.com/deepinsight/insightface.git
synced 2026-07-22 06:30:59 +00:00
Update InspireFace to 1.1.4
This commit is contained in:
@@ -3,6 +3,12 @@ import cv2
|
||||
import inspireface as ifac
|
||||
from inspireface.param import *
|
||||
import click
|
||||
import numpy as np
|
||||
|
||||
race_tags = ["Black", "Asian", "Latino/Hispanic", "Middle Eastern", "White"]
|
||||
gender_tags = ["Female", "Male", ]
|
||||
age_bracket_tags = ["0-2 years old", "3-9 years old", "10-19 years old", "20-29 years old", "30-39 years old",
|
||||
"40-49 years old", "50-59 years old", "60-69 years old", "more than 70 years old"]
|
||||
|
||||
@click.command()
|
||||
@click.argument("resource_path")
|
||||
@@ -17,7 +23,7 @@ def case_face_detection_image(resource_path, image_path):
|
||||
assert ret, "Launch failure. Please ensure the resource path is correct."
|
||||
|
||||
# Optional features, loaded during session creation based on the modules specified.
|
||||
opt = HF_ENABLE_FACE_RECOGNITION | HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS
|
||||
opt = HF_ENABLE_FACE_RECOGNITION | HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS | HF_ENABLE_INTERACTION | HF_ENABLE_FACE_ATTRIBUTE
|
||||
session = ifac.InspireFaceSession(opt, HF_DETECT_MODE_ALWAYS_DETECT)
|
||||
|
||||
# Load the image using OpenCV.
|
||||
@@ -35,12 +41,33 @@ def case_face_detection_image(resource_path, image_path):
|
||||
print(f"idx: {idx}")
|
||||
# Print Euler angles of the face.
|
||||
print(f"roll: {face.roll}, yaw: {face.yaw}, pitch: {face.pitch}")
|
||||
# Draw bounding box around the detected face.
|
||||
|
||||
# Get face bounding box
|
||||
x1, y1, x2, y2 = face.location
|
||||
cv2.rectangle(draw, (x1, y1), (x2, y2), (0, 0, 255), 2)
|
||||
|
||||
# Calculate center, size, and angle
|
||||
center = ((x1 + x2) / 2, (y1 + y2) / 2)
|
||||
size = (x2 - x1, y2 - y1)
|
||||
angle = face.roll # 这里使用 roll 角度
|
||||
|
||||
# Get rotation matrix
|
||||
rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
|
||||
|
||||
# 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)
|
||||
|
||||
# Features must be enabled during session creation to use them here.
|
||||
select_exec_func = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS
|
||||
select_exec_func = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS | HF_ENABLE_INTERACTION | HF_ENABLE_FACE_ATTRIBUTE
|
||||
# Execute the pipeline to obtain richer face information.
|
||||
extends = session.face_pipeline(image, faces, select_exec_func)
|
||||
for idx, ext in enumerate(extends):
|
||||
@@ -50,6 +77,11 @@ def case_face_detection_image(resource_path, image_path):
|
||||
print(f"quality: {ext.quality_confidence}")
|
||||
print(f"rgb liveness: {ext.rgb_liveness_confidence}")
|
||||
print(f"face mask: {ext.mask_confidence}")
|
||||
print(
|
||||
f"face eyes status: left eye: {ext.left_eye_status_confidence} right eye: {ext.right_eye_status_confidence}")
|
||||
print(f"gender: {gender_tags[ext.gender]}")
|
||||
print(f"race: {race_tags[ext.race]}")
|
||||
print(f"age: {age_bracket_tags[ext.age_bracket]}")
|
||||
|
||||
# Save the annotated image to the 'tmp/' directory.
|
||||
save_path = os.path.join("tmp/", "det.jpg")
|
||||
|
||||
Reference in New Issue
Block a user