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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started