Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ target/
.python-version

.idea/
.venv/
11 changes: 9 additions & 2 deletions examples/digital_makeup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
face_landmarks_list = face_recognition.face_landmarks(image)

pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image, 'RGBA')

for face_landmarks in face_landmarks_list:
d = ImageDraw.Draw(pil_image, 'RGBA')

# Make the eyebrows into a nightmare
d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
Expand All @@ -31,4 +32,10 @@
d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6)
d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6)

pil_image.show()
# Create a side-by-side comparison of the original and the digital makeup
final_image = Image.new('RGB', (pil_image.width * 2, pil_image.height))
final_image.paste(Image.fromarray(image), (0, 0))
final_image.paste(pil_image, (pil_image.width, 0))

# Show the results
final_image.show()
24 changes: 22 additions & 2 deletions examples/find_faces_in_picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

print("I found {} face(s) in this photograph.".format(len(face_locations)))

import math

# Create a list of all found faces
face_images = []
for face_location in face_locations:

# Print the location of each face in this image
Expand All @@ -19,5 +23,21 @@

# You can access the actual face itself like this:
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
pil_image.show()
face_images.append(Image.fromarray(face_image))

if face_images:
# Build a grid of the faces
n = len(face_images)
cols = math.ceil(math.sqrt(n))
rows = math.ceil(n / cols)

# Use a fixed thumb size for the grid
thumb_size = 150
grid_image = Image.new('RGB', (cols * thumb_size, rows * thumb_size))

for i, face in enumerate(face_images):
face = face.resize((thumb_size, thumb_size))
grid_image.paste(face, ((i % cols) * thumb_size, (i // cols) * thumb_size))

# Show the final grid of faces
grid_image.show()
24 changes: 22 additions & 2 deletions examples/find_faces_in_picture_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

print("I found {} face(s) in this photograph.".format(len(face_locations)))

import math

# Create a list of all found faces
face_images = []
for face_location in face_locations:

# Print the location of each face in this image
Expand All @@ -21,5 +25,21 @@

# You can access the actual face itself like this:
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
pil_image.show()
face_images.append(Image.fromarray(face_image))

if face_images:
# Build a grid of the faces
n = len(face_images)
cols = math.ceil(math.sqrt(n))
rows = math.ceil(n / cols)

# Use a fixed thumb size for the grid
thumb_size = 150
grid_image = Image.new('RGB', (cols * thumb_size, rows * thumb_size))

for i, face in enumerate(face_images):
face = face.resize((thumb_size, thumb_size))
grid_image.paste(face, ((i % cols) * thumb_size, (i // cols) * thumb_size))

# Show the final grid of faces
grid_image.show()