Detect & Unskew a Photo of a Document in Python
If you’re making a document processing application (in particular, a document scanning application), this API is for you: the /image/recognize/detect-document/unskew iteration of the Cloudmersive Image API can detect & unskew a photo of a document into a perfectly square image. You can even use this in conjunction with Cloudmersive’s Conversion & Optical Character Recognition APIs to create a seamless document processing flow. Below, we’ll walk through connecting to this API in Python using code directly from the Cloudmersive API console.
To start connecting, use this command to install the Python SDK:
pip install cloudmersive-image-api-client
Following that, kickoff the API callback function starting with the two snippets below. The latter of the two will capture & authenticate your Cloudmersive API key, so make sure to have that handy:
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'
Then, you can wrap things up with the below code:
# 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.
post_processing_effect = 'post_processing_effect_example' # str | Optional, post-processing effects to apply to the email, default is None. Possible values are None and BlackAndWhite (force the image into a black and white view to aid in OCR operations). (optional)try:
# Detect and unskew a photo of a document
api_response = api_instance.recognize_detect_and_unskew_document(image_file, post_processing_effect=post_processing_effect)
except ApiException as e:
print("Exception when calling RecognizeApi->recognize_detect_and_unskew_document: %s\n" % e)