السلام عليكم
# face-recognition
import face_recognition
import numpy
from PIL import Image , ImageDraw
# David Malan
# تحميل الصوره
david = face_recognition.load_image_file("David.png")
harvard = face_recognition.load_image_file("Harvard.jpg")
# locations and encodins face
david_encoding = face_recognition.face_encodings(david)[0]
harvard_locations = face_recognition.face_locations(harvard)
harvard_encoding = face_recognition.face_encodings(harvard , harvard_locations)
# draw in Image
pil_image = Image.fromarray(harvard)
draw = ImageDraw.Draw(pil_image)
# for loop
for (top , right , bottom , left) , face_encodeing in zip(harvard_locations , harvard_encoding):
matches = face_recognition.compare_faces([david_encoding] , face_encodeing)
best_match_index = numpy.argmin(matches)
if matches[best_match_index]:
box_color = "green"
else:
box_color = "red"
draw.rectangle(((left,top) , (right,bottom)), outline=box_color , width=5)
if matches[best_match_index]:
text = "David Malan"
else:
text = "Unknown"
draw.text((left,top - 20), text, fill=box_color, font=None)
pil_image.save("harvard.jpg"