File size: 1,857 Bytes
a214903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
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)