Search⌘ K
AI Features

Displaying and Framing Faces in an Image

Explore how to use Azure Face API to detect faces in images and frame them by drawing rectangles. Understand the implementation of client setup, image processing, and drawing functions to highlight identified faces effectively.

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.

C++
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 ...