Usando IA para calcular semelhança familiar
Sempre há quem diga que seu filho se parece mais com a mãe ou com o pai. Que tal usar matemática e Inteligência Artificial para ter certeza? O aplicativo facial-matching pode te dar a resposta.
Veja os resultados:
- Faça update das fotos do Pai, da Mãe e da Criança.:

2.Clique no botão Calcular Semelhança (Calculate Resemblance) e veja os resultados:

Detalhes de implementação
1.Obtem os arquivos de imagem do pai, da criança e da mãe.:
father_file = request.files['father_image']
child_file = request.files['child_image']
mother_file = request.files['mother_image']
2. Usa a biblioteca CV2 para codificar as imagens.:
father_img = cv2.imdecode(np.frombuffer(father_file.read(), np.uint8), cv2.IMREAD_COLOR)
child_img = cv2.imdecode(np.frombuffer(child_file.read(), np.uint8), cv2.IMREAD_COLOR)
mother_img = cv2.imdecode(np.frombuffer(mother_file.read(), np.uint8), cv2.IMREAD_COLOR)
3. Compara pai e filho usando o Deepface verify:
father_verification = DeepFace.verify(
img1_path=child_img,
img2_path=father_img,
model_name="VGG-Face",
detector_backend="retinaface",
enforce_detection=True
)
4. Compara mãe e filho usando o Deepface.verify:
mother_verification = DeepFace.verify(
img1_path=child_img,
img2_path=mother_img,
model_name="VGG-Face",
detector_backend="retinaface",
enforce_detection=True
)
5. Calcula os percentuais de semelhança:
father_similarity = 1 - father_verification['distance']
mother_similarity = 1 - mother_verification['distance']
return jsonify({
"resemblance_to_father": father_similarity * 100,
"resemblance_to_mother": mother_similarity * 100
})
6. Aproveite esta solução!
Ir para o posto original escrito por @Yuri Marx
Discussão (0)0