File size: 1,489 Bytes
3744cfc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from deepface import DeepFace

def compare_faces():
    results = []

    # ์—ฌ์ž ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
    female_image_paths = [f"images/F_{i}.jpg" for i in range(1, 23)]

    for male_index in range(1, 33):
        # ๋‚จ์ž ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ
        male_image_path = f"images/M_{male_index}.jpg"
        
        max_similarity = -1
        min_similarity = float('inf')
        most_similar = None
        least_similar = None

        for female_image_path in female_image_paths:
            result = DeepFace.verify(male_image_path, female_image_path)
            similarity = 1 - result["distance"]
            
            if similarity > max_similarity:
                max_similarity = similarity
                most_similar = female_image_path
            
            if similarity < min_similarity:
                min_similarity = similarity
                least_similar = female_image_path

        most_similar_name = os.path.basename(most_similar)
        least_similar_name = os.path.basename(least_similar)

        results.append(
            f"๋‚จ์ž M_{male_index}:\n"
            f"  ๊ฐ€์žฅ ์œ ์‚ฌ๋„๊ฐ€ ๋†’์€ ์‚ฌ๋žŒ: {most_similar_name} (์œ ์‚ฌ๋„: {max_similarity:.2f})\n"
            f"  ๊ฐ€์žฅ ์œ ์‚ฌ๋„๊ฐ€ ๋‚ฎ์€ ์‚ฌ๋žŒ: {least_similar_name} (์œ ์‚ฌ๋„: {min_similarity:.2f})"
        )

    return "\n\n".join(results)

def main():
    results = compare_faces()
    print(results)

if __name__ == "__main__":
    main()