|
import os |
|
from deepface import DeepFace |
|
|
|
def compare_faces(): |
|
results = [] |
|
|
|
|
|
female_image_paths = [f"images/{i}_F.jpg" for i in range(1, 23)] |
|
|
|
for male_index in range(1, 33): |
|
|
|
male_image_path = f"images/{male_index}_M.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() |
|
|