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. 

Original Article

Face Detection Tutorial

Martin W Brennan Martin W Brennan is a co-founder of ViewPop, the social network that puts the creation of 3D photos and videos in the hands of anyone with a smartphone. For his day job, Martin is a copywriting consultant at We Write Words, learning about the world as he writes about it.