Detect People (including Locations) in an Image in Python
It’s fine to crop images of people without opening them as long as you know where people are within the image. After all, we don’t want a cropped image with half of a leg sticking out of one side. Using the Cloudmersive Image API, you can identify the position & size of human people in the image, and receive a ‘confidence level’ score determining how likely that identification is to be correct. This API isn’t relying on facial recognition, so it’s fine if people in the image aren’t facing towards the camera. The locational information you’ll receive will make any un-opened edits much more effective before the next actions you want to take. Below, I’ll walk you through connecting to this API in Python using code from the Cloudmersive API Console.
The first step is to copy & run the below command. This will install the Python SDK:
pip install cloudmersive-image-api-client
After that, you can copy & paste the below code to call the API. Make sure to fill in any information where indicated in the documentation, including copying your Cloudmersive API key into the correct area. If you don’t already have a key, you can get one easily by making a free account on the Cloudmersive website (this will provide 800 free monthly API calls).
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'# create an instance of the API class
api_instance = cloudmersive_image_api_client.RecognizeApi(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 people including locations in an image
api_response = api_instance.recognize_detect_people(image_file)
except ApiException as e:
print("Exception when calling RecognizeApi->recognize_detect_people: %s\n" % e)