Detect Objects including Types and Locations in an Image in Python
Many images are made up of various conventional subjects, whether those be people, buildings, animals, or anything else. For a variety of reasons, it can be useful to have information about the subjects within an image such as their position, size, and a brief description of those subjects without opening the image itself. The Cloudmersive Image API can provide this information automatically concerning both human people and objects, complete with a ‘Confidence Level’ score determining how likely the description is to be correct. It’s easy to connect using ready-to-go, documented code from the Cloudmersive API Console. Let’s look at how you can connect in Python.
To begin connecting, first run the Python SDK installation command:
pip install cloudmersive-image-api-client
Following that, you can copy in the remaining code to complete the API call. In the middle snippet below, you’ll be prompted to input your Cloudmersive API key, which can be obtained easily by creating a free account on the Cloudmersive website. Otherwise, you’ll just need to include the file for the operation, and you’re all set to go.
from __future__ import print_function
import time
import cloudmersive_image_api_client
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 objects including types and locations in an image
api_response = api_instance.recognize_detect_objects(image_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling RecognizeApi->recognize_detect_objects: %s\n" % e)