Using AI to calculate family resemblance
There are always those who say that their child looks more like their mother or their father. How about using math and Artificial Intelligence to be sure? The facial-matching application can answer you.
See these results:
- Upload Father, Child and Mother photos:

2. Click the button Calculate Resemblance and see the results:

Implementation details
1.Get the image files for father, child and mother:
father_file = request.files['father_image']
child_file = request.files['child_image']
mother_file = request.files['mother_image']2. Use CV2 library to encode the images:
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. Compare father and child using 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. Compare mother and child using 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. Calculate similary percentages:
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. Enjoy this solution!
Discussion (0)0