Detect and Find Faces & Landmarks (Eyes, Nose, Mouth) in an Image in Python
In a prior article, we walked through an iteration of the Cloudmersive Image API which can detect & locate faces in an image. Now, we’ll take a look at the /image/face/locate-with-landmarks iteration the Image API, which takes a deeper dive into the detected faces in an image and accounts for important features like eyes, brows, nose & mouth. The resulting API call will give you specific coordinates for each face in the image along with locational information about each face’s detected facial features.
To leverage this API, first copy & run the below command in your environment:
pip install cloudmersive-image-api-client
Next, you can use the below code to kickoff the callback function & authenticate your Cloudmersive API key:
from __future__ import print_function
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
If you don’t currently have a key, you can easily make one by visiting Cloudmersive.com and creating a free account (this will provide 800 free API calls per month).
Now, to wrap up, simply copy the remaining code below:
# create an instance of the API class
api_instance = cloudmersive_image_api_client.FaceApi(cloudmersive_image_api_client.ApiClient(configuration))
image_file = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try:
# Detect and find faces and landmarks eyes and nose and mouth in image
api_response = api_instance.face_locate_with_landmarks(image_file)
except ApiException as e:
print("Exception when calling FaceApi->face_locate_with_landmarks: %s\n" % e)