Question: Using PIL, which is the Python Image Library. write Python code to detect faces in an image. Use the following Python code as a starter

Using PIL, which is the Python Image Library. write Python code to detect faces in an image. Use the following Python code as a starter for your program.

Supply your own image file that contains one or more faces to identify. An example output for your program should be something like the following picture with red boxes (instead of green) drawn around each individuals face:

import PIL.ImageDraw

import face_recognition

# Load the jpg file into a numpy array

# Find all the faces in the image # Use the following Python pseudocode as guidance for your solution.

numberOfFaces = len(faceLocations)print("Found {} face(s) in this picture.".format(numberOfFaces))

# Load the image into a Python Image Library object so that you can draw on top of it and display it

pilImage = PIL.Image.fromarray(image)

for faceLocation in faceLocations:

# Print the location of each face in this image. Each face is a list of co-ordinates in (top, right, bottom, left) order.

print("A face is located at pixel location Top: {}, Left {},Bottom: {}, Right: {}".format(top, left, bottom, right))

# Draw a box around the face drawHandle = PIL.ImageDraw.Draw(pilImage) drawHandle.rectangle([left, top, right, bottom], outline="red")

# Display the image on screenpilImage.show()

Develop the remaining code in the section specific to face detection.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!