Compare and Match Faces in Python
Leveraging a combination of biometrics and Machine Learning techniques, the Cloudmersive Image API is a powerful utility-API tool with a variety of useful applications. Using the /image/face/compare-and-match iteration, you can detect multiple faces in one image and compare them with a single face in a separate image to determine if there’s a match based on facial landmarks. Let’s take a look at how easy it is to connect with this API in Python using ready-to-run code from the Cloudmersive API Console.
To begin, run the below command to install the Python SDK:
pip install cloudmersive-image-api-client
Next, you can start the call function with the below code. Make sure you have your Cloudmersive API key handy for this step:
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'
Finally, wrap up the function with the below snippet, and you’re ready to go:
# create an instance of the API class
api_instance = cloudmersive_image_api_client.FaceApi(cloudmersive_image_api_client.ApiClient(configuration))
input_image = '/path/to/inputfile' # file | Image file to perform the operation on; this image can contain one or more faces which will be matched against face provided in the second image. Common file formats such as PNG, JPEG are supported.
match_face = '/path/to/inputfile' # file | Image of a single face to compare and match against.try:
# Compare and match faces
api_response = api_instance.face_compare(input_image, match_face)
except ApiException as e:
print("Exception when calling FaceApi->face_compare: %s\n" % e)