Spaces:
Sleeping
Sleeping
Download modeles/verify_folder_against_template.py from VisionShield/VISIONSHIELD: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/spaces/VisionShield/VISIONSHIELD/resolve/refs%2Fpr%2F1/modeles/verify_folder_against_template.py
- Command line
-
hf download hf://spaces/VisionShield/VISIONSHIELD@refs/pr/1/modeles/verify_folder_against_template.py
-
curl -L -o verify_folder_against_template.py https://huggingface.co/spaces/VisionShield/VISIONSHIELD/resolve/refs%2Fpr%2F1/modeles/verify_folder_against_template.py
1.86 kB
| import os | |
| from modeles import deepface_template_utils as dtu | |
| import cv2 | |
| def auto_rotate_if_needed(image_path): | |
| img = cv2.imread(image_path) | |
| if img is None: | |
| raise ValueError(f"Image non lisible : {image_path}") | |
| h, w = img.shape[:2] | |
| # Si l'image est couchée (plus large que haute) | |
| if w > h: | |
| img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE) | |
| cv2.imwrite(image_path, img) | |
| return image_path | |
| def verify_images_in_folder(test_folder, template_path, threshold=0.5): | |
| template = dtu.load_template(template_path) | |
| total = 0 | |
| matches = 0 | |
| mismatches = 0 | |
| errors = 0 | |
| for filename in os.listdir(test_folder): | |
| if not filename.lower().endswith((".jpg", ".jpeg", ".png")): | |
| continue | |
| image_path = os.path.join(test_folder, filename) | |
| total += 1 | |
| try: | |
| result, score = dtu.verify_against_template(image_path, template, threshold=threshold) | |
| if result: | |
| matches += 1 | |
| print(f"✅ {filename} : MATCH ({score:.4f})") | |
| else: | |
| mismatches += 1 | |
| print(f"❌ {filename} : NO MATCH ({score:.4f})") | |
| except Exception as e: | |
| errors += 1 | |
| print(f"⚠️ Erreur sur {filename} : {e}") | |
| print("\n=== Résumé ===") | |
| print(f"🖼️ Total images testées : {total}") | |
| print(f"✅ Correspondances : {matches}") | |
| print(f"❌ Non correspondantes : {mismatches}") | |
| print(f"⚠️ Erreurs : {errors}") | |
| # Exemple d’appel depuis main.py : | |
| if __name__ == "__main__": | |
| test_folder = r"C:\Users\lisig\Desktop\Vision_shield_projet\IA_objets\Lina\Lina_images_ref\IMG_3955" | |
| template_path = r"C:\Users\lisig\Desktop\Vision_shield_projet\IA_objets\lina_template.json" | |
| verify_images_in_folder(test_folder, template_path, threshold=0.5) | |