Spaces:
Sleeping
Sleeping
File size: 1,455 Bytes
a94c5c8 88e55d3 a94c5c8 88e55d3 a94c5c8 88e55d3 a94c5c8 88e55d3 a94c5c8 88e55d3 a94c5c8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import os
import cv2
import numpy as np
from insightface.app import FaceAnalysis
def check_liveness_on_folder(folder_path, frame_interval=1, yaw_thresh=5, pitch_thresh=5):
model = FaceAnalysis(name='buffalo_l', providers=['CPUExecutionProvider'])
model.prepare(ctx_id=0)
poses = []
image_files = sorted([
f for f in os.listdir(folder_path)
if f.lower().endswith((".jpg", ".jpeg", ".png"))
])
for idx, filename in enumerate(image_files):
if idx % frame_interval != 0:
continue
img_path = os.path.join(folder_path, filename)
img = cv2.imread(img_path)
if img is None:
print(f"Image illisible : {filename}")
return False
faces = model.get(img)
if not faces:
print(f"Aucun visage détecté sur {filename}")
return False
pose = faces[0].pose # [yaw, pitch, roll]
poses.append(pose)
if len(poses) < 3:
print("Pas assez de données pour vérifier la vivacité.")
return False
poses = np.array(poses)
yaw_std = np.std(poses[:, 0])
pitch_std = np.std(poses[:, 1])
print(f"Écarts-types — Yaw: {yaw_std:.2f}, Pitch: {pitch_std:.2f}")
if yaw_std < yaw_thresh and pitch_std < pitch_thresh:
print("Visage figé détecté — FAKE")
return False
else:
print("🟢 Mouvement naturel détecté — REAL")
return True
|