...

/

Displaying and Framing Faces in an Image

Displaying and Framing Faces in an Image

Learn to detect and frame the faces identified using the Azure Face SDK.

We'll cover the following...

Introduction

In the previous lesson, we learned how to detect faces in an image. Now we’ll explore how we can create frames across all the faces that are identified in the image.

Implementation

Let’s look at the implementation of this functionality.

Press + to interact
Please provide values for the following:
face_api_key
Not Specified...
face_api_endpoint
Not Specified...
main.py
draw.py
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
import shutil
from draw import draw_rectangles
client = FaceClient(
face_api_endpoint,
CognitiveServicesCredentials(face_api_key)
)
image_url = "https://cdn.pixabay.com/photo/2017/01/14/10/56/people-1979261_1280.jpg"
detected_faces = client.face.detect_with_url(url = image_url)
if not detected_faces:
print("No face detected from image.")
else:
draw_rectangles(image_url, detected_faces)
# Do not modify the below lines as these are required to view the output in the browser.
shutil.copy2('./image.png', './output/image.png')

Explanation

The explanation of main.py file is given below:

  • From lines 1-4, we import the required packages.

  • From lines 6-9, we ...