import face_recognition
from PIL import Image, ImageDraw

image_of_bill = face_recognition.load_image_file('./img/known/Bill Gates.jpg')
bill_face_encoding = face_recognition.face_encodings(image_of_bill)[0]

image_of_steve = face_recognition.load_image_file('./img/known/Steve Jobs.jpg')
steve_face_encoding = face_recognition.face_encodings(image_of_steve)[0]


# Create array of encodings and names
known_face_encodings = [
    bill_face_encoding,
    steve_face_encoding
]

known_face_names = [
    "Bill Gates",
    "Steve Jobs"
]

# Load the test image to find faces in
test_image = face_recognition.load_image_file(
    './img/groups/bill-steve-elon.jpg')

# Find faces in test image
face_locations = face_recognition.face_locations(test_image)
face_encodings = face_recognition.face_encodings(test_image, face_locations)

# Convert to PIL format
pil_image = Image.fromarray(test_image)

# Create a ImageDraw instance
draw = ImageDraw.Draw(pil_image)

# Loop trough faces in test image
for(top, rigth, bottom, left), face_encoding in zip(face_locations, face_encodings):
    matches = face_recognition.compare_faces(
        known_face_encodings, face_encoding)

    name = "Unknown Person"

    # If match
    if True in matches:
        first_match_index = matches.index(True)
        name = known_face_names[first_match_index]

    # Draw the box
    draw.rectangle(((left, top), (rigth, bottom)), outline=(0, 0, 0))

    # Draw the label
    text_width, text_heigth = draw.textsize(name)
    draw.rectangle(((left, bottom - text_heigth - 10),
                    (rigth, bottom)), fill=(0, 0, 0), outline=(0, 0, 0))
    draw.text((left + 6, bottom - text_heigth - 5),
              name, fill=(255, 255, 255, 255))

del draw

# Display the image
pil_image.show()
pil_image.save('identify.jpg')

3cfd7925e6af59f26c0dc0ce9a352964b649915c
<mask token>

<mask token>
for (top, rigth, bottom, left), face_encoding in zip(face_locations,
    face_encodings):
    matches = face_recognition.compare_faces(known_face_encodings,
        face_encoding)
    name = 'Unknown Person'
    if True in matches:
        first_match_index = matches.index(True)
        name = known_face_names[first_match_index]
    draw.rectangle(((left, top), (rigth, bottom)), outline=(0, 0, 0))
    text_width, text_heigth = draw.textsize(name)
    draw.rectangle(((left, bottom - text_heigth - 10), (rigth, bottom)),
        fill=(0, 0, 0), outline=(0, 0, 0))
    draw.text((left + 6, bottom - text_heigth - 5), name, fill=(255, 255, 
        255, 255))
del draw
pil_image.show()
pil_image.save('identify.jpg')

<mask token>
image_of_bill = face_recognition.load_image_file('./img/known/Bill Gates.jpg')
bill_face_encoding = face_recognition.face_encodings(image_of_bill)[0]
image_of_steve = face_recognition.load_image_file('./img/known/Steve Jobs.jpg')
steve_face_encoding = face_recognition.face_encodings(image_of_steve)[0]
known_face_encodings = [bill_face_encoding, steve_face_encoding]
known_face_names = ['Bill Gates', 'Steve Jobs']
test_image = face_recognition.load_image_file(
    './img/groups/bill-steve-elon.jpg')
face_locations = face_recognition.face_locations(test_image)
face_encodings = face_recognition.face_encodings(test_image, face_locations)
pil_image = Image.fromarray(test_image)
draw = ImageDraw.Draw(pil_image)
for (top, rigth, bottom, left), face_encoding in zip(face_locations,
    face_encodings):
    matches = face_recognition.compare_faces(known_face_encodings,
        face_encoding)
    name = 'Unknown Person'
    if True in matches:
        first_match_index = matches.index(True)
        name = known_face_names[first_match_index]
    draw.rectangle(((left, top), (rigth, bottom)), outline=(0, 0, 0))
    text_width, text_heigth = draw.textsize(name)
    draw.rectangle(((left, bottom - text_heigth - 10), (rigth, bottom)),
        fill=(0, 0, 0), outline=(0, 0, 0))
    draw.text((left + 6, bottom - text_heigth - 5), name, fill=(255, 255, 
        255, 255))
del draw
pil_image.show()
pil_image.save('identify.jpg')

import face_recognition
from PIL import Image, ImageDraw
image_of_bill = face_recognition.load_image_file('./img/known/Bill Gates.jpg')
bill_face_encoding = face_recognition.face_encodings(image_of_bill)[0]
image_of_steve = face_recognition.load_image_file('./img/known/Steve Jobs.jpg')
steve_face_encoding = face_recognition.face_encodings(image_of_steve)[0]
known_face_encodings = [bill_face_encoding, steve_face_encoding]
known_face_names = ['Bill Gates', 'Steve Jobs']
test_image = face_recognition.load_image_file(
    './img/groups/bill-steve-elon.jpg')
face_locations = face_recognition.face_locations(test_image)
face_encodings = face_recognition.face_encodings(test_image, face_locations)
pil_image = Image.fromarray(test_image)
draw = ImageDraw.Draw(pil_image)
for (top, rigth, bottom, left), face_encoding in zip(face_locations,
    face_encodings):
    matches = face_recognition.compare_faces(known_face_encodings,
        face_encoding)
    name = 'Unknown Person'
    if True in matches:
        first_match_index = matches.index(True)
        name = known_face_names[first_match_index]
    draw.rectangle(((left, top), (rigth, bottom)), outline=(0, 0, 0))
    text_width, text_heigth = draw.textsize(name)
    draw.rectangle(((left, bottom - text_heigth - 10), (rigth, bottom)),
        fill=(0, 0, 0), outline=(0, 0, 0))
    draw.text((left + 6, bottom - text_heigth - 5), name, fill=(255, 255, 
        255, 255))
del draw
pil_image.show()
pil_image.save('identify.jpg')

import face_recognition
from PIL import Image, ImageDraw

image_of_bill = face_recognition.load_image_file('./img/known/Bill Gates.jpg')
bill_face_encoding = face_recognition.face_encodings(image_of_bill)[0]

image_of_steve = face_recognition.load_image_file('./img/known/Steve Jobs.jpg')
steve_face_encoding = face_recognition.face_encodings(image_of_steve)[0]


# Create array of encodings and names
known_face_encodings = [
    bill_face_encoding,
    steve_face_encoding
]

known_face_names = [
    "Bill Gates",
    "Steve Jobs"
]

# Load the test image to find faces in
test_image = face_recognition.load_image_file(
    './img/groups/bill-steve-elon.jpg')

# Find faces in test image
face_locations = face_recognition.face_locations(test_image)
face_encodings = face_recognition.face_encodings(test_image, face_locations)

# Convert to PIL format
pil_image = Image.fromarray(test_image)

# Create a ImageDraw instance
draw = ImageDraw.Draw(pil_image)

# Loop trough faces in test image
for(top, rigth, bottom, left), face_encoding in zip(face_locations, face_encodings):
    matches = face_recognition.compare_faces(
        known_face_encodings, face_encoding)

    name = "Unknown Person"

    # If match
    if True in matches:
        first_match_index = matches.index(True)
        name = known_face_names[first_match_index]

    # Draw the box
    draw.rectangle(((left, top), (rigth, bottom)), outline=(0, 0, 0))

    # Draw the label
    text_width, text_heigth = draw.textsize(name)
    draw.rectangle(((left, bottom - text_heigth - 10),
                    (rigth, bottom)), fill=(0, 0, 0), outline=(0, 0, 0))
    draw.text((left + 6, bottom - text_heigth - 5),
              name, fill=(255, 255, 255, 255))

del draw

# Display the image
pil_image.show()
pil_image.save('identify.jpg')
