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()
|