This script will process a directory of images through the Microsoft Azure Cognitive Services API Face API and save the resulting face age and emotion scores to a csv file.
This script requires the requests library:
$ pip install requests
The Azure Face API requires a subscription key (you can sign up for a free account
here) which should be
specified in a .cfg
file using the format below:
[Subscription]
key = 12345abcd678910efghijk
url = https://uksouth.api.cognitive.microsoft.com/face/v1.0/detect
The url
argument in the configuration file can be changed to match the closest region.
The script assumes you are using one of the free tier subscriptions so requests are rate
limited to one every 5 seconds (the limit is 20 requests per min).
To run the script pass the configuration file, image directory and output file as arguments to the script:
$ python faceage.py -c config.cfg -i images -o results.csv
The results as saved in csv file format. Values for age, gender and emotion scores are
returned for each image file along with the faceId
value assigned by Azure.