You are here

How to Detect Faces With the Google Cloud Vision API

The Google Cloud Vision API is currently in Beta and available to developers with a basic pricing model that is free up to a thousand units per month. That means that developers have access to powerful image analysis capabilities backed by Google’s Machine Vision Infrastructure to implement in any relevant project.

The technology uses Machine Learning to identify the content in images, such as objects, colors, and notable landmarks. That data can be leveraged by applications or other software to perform specific tasks according to the developer’s intentions. In this tutorial on Google Cloud Platform, followers learn how to use the Google Cloud Vision API to detect faces in an image, and use that data to draw a box around each face.

Followers are expected to have a project set up in the Google Cloud Platform console, and have pip and the Google API Python client installed. The tutorial begins with creating the service object based on the API’s discovery document that describes the API to the SDK.

Constructing a request to the Vision API for this tutorial means asking the images  Resource to annotate your image. Each of these requests acts as an object with a requests list that holds two bits of info. The first is the base64-encoded image data, and the second is the list of features you want to be annotated, which will be FACE_DETECTION in this case.

The response contains metadata about any faces that were detected in the image, including the coordinates of a polygon surrounding each face. The author then uses these coordinates to draw a polygon onto a copy of the image as the final output. Code samples are provided, along with links to the larger projects on GitHub from which each code sample is taken. 

Be sure to read the next Images article: How Image Tagging APIs from Google, Amazon, Microsoft and Clarifai Stack Up

Original Article

Face Detection Tutorial