Spaces:
Sleeping
Sleeping
Update modeles/insightface_facialRecognition_livenessVerification.py
Browse files
modeles/insightface_facialRecognition_livenessVerification.py
CHANGED
|
@@ -2,10 +2,19 @@ import cv2
|
|
| 2 |
import numpy as np
|
| 3 |
import insightface
|
| 4 |
|
| 5 |
-
model =
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def verify_face_and_liveness(image_path, template_path, threshold=0.5):
|
|
|
|
|
|
|
| 9 |
img = cv2.imread(image_path)
|
| 10 |
if img is None:
|
| 11 |
raise ValueError("❌ Image illisible")
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import insightface
|
| 4 |
|
| 5 |
+
model = None
|
| 6 |
+
|
| 7 |
+
def get_model():
|
| 8 |
+
global model
|
| 9 |
+
if model is None:
|
| 10 |
+
model_dir = os.path.join(os.path.dirname(__file__), "../models") # <-- Chemin local
|
| 11 |
+
model = insightface.app.FaceAnalysis(name="buffalo_l", root=model_dir, providers=["CPUExecutionProvider"])
|
| 12 |
+
model.prepare(ctx_id=0)
|
| 13 |
+
return model
|
| 14 |
|
| 15 |
def verify_face_and_liveness(image_path, template_path, threshold=0.5):
|
| 16 |
+
model = get_model()
|
| 17 |
+
|
| 18 |
img = cv2.imread(image_path)
|
| 19 |
if img is None:
|
| 20 |
raise ValueError("❌ Image illisible")
|