File size: 1,633 Bytes
3744cfc 1df249d c43d0de 1df249d 3744cfc bb1abca 3744cfc 1df249d 3744cfc 1df249d 3744cfc ad9c01c |
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 |
import os
from deepface import DeepFace
def compare_faces():
results = []
# ๋จ์ ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก ๋ฆฌ์คํธ ์์ฑ
male_image_paths = [f"images/{i}_M.jpeg" for i in range(1, 33)]
# ์ฌ์ ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก ๋ฆฌ์คํธ ์์ฑ
female_image_paths = [f"images/{i}_F.jpeg" for i in range(1, 23)]
for male_index in range(1, 33):
# ๋จ์ ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก
male_image_path = f"images/{male_index}_M.jpeg"
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, enforce_detection=False)
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()
|