Microsoft Azure Ink Recognizer Library for Python
Project description
Azure Ink Recognizer client library for Python
Azure Ink Recognizer SDK is an SDK for developers to work with Azure Ink Recognizer Service. The service recognize a collection of ink strokes and return a tree hierarchy of the recognized units, such as lines, words, shapes, as well as the handwriting recognition result of the words.
Features:
- Connect to Azure Ink Recognizer Service
- Convert collections of ink strokes into HTTP requests
- Parse HTTP response into ink recognition units
Source code | Package (PyPi) | API reference documentation | Product documentation | Samples
Getting started
Install the package
Install the Azure Cosmos DB client library for Python with pip:
pip install azure-cognitiveservices-inkrecognizer
Prerequisites: You must have an Azure subscription. You must have Python 2.7 or Python 3.5.3+ to use this package. Asynchronous features supports Python 3.5.3+ only.
Get URL
Please find the URL at Ink Recognizer Rest API documentation
Get credentials
Please follow the instructions on Ink Recognizer.
Key concepts
Implement ink stroke
If you don't have any pre-defined ink point or ink stroke classes, you can either follow the Ink Stroke Interfaces to build your stroke, or build your own class that has all required fields. If you already defined ink strokes yourself, you should feed attributes in your class according to the interfaces.
from azure.cognitiveservices.inkrecognizer import InkStrokeKind
InkPoint = namedtuple("InkPoint", "x y")
class InkStroke():
def __init__(self,
ink_stroke_id,
ink_points,
stroke_kind=InkStrokeKind.UNKNOWN,
stroke_language=""):
self.id = ink_stroke_id
self.points = ink_points
self.kind = stroke_kind
self.language = stroke_language
You can then create a list (or any iterable object) of ink strokes for recognition.
Create a client
Once you got the url for ink recognizer service and an Azure credential instance, you can create an InkRecognizerClient
from azure.cognitiveservices.inkrecognizer import InkRecognizerClient
client = InkRecognizerClient(url, api_key) # api_key is your key as string
Or use Async version (Python 3.5.3+ only)
from azure.cognitiveservices.inkrecognizer.aio import InkRecognizerClient
client = InkRecognizerClient(url, api_key) # api_key is your key as string
Send a request
You can then send stroke list to Ink Recognizer Service and get the root of all ink recognition results.
# Sync version
recognition_root = client.recognize_ink(ink_stroke_list)
# Async version
recognition_root = await client.recognize_ink(ink_stroke_list)
Get recognition units from results
You can get all the recognition units either by InkRecognitionUnitKind or by hierarchy, then visit support properties of the units. API reference documentation
lines = recognition_root.lines
for line in lines:
foo_show_bounding_box(line.bounding_box)
for word in line.words:
print(word.recognized_text)
Examples
The Samples provide several code snippets covering some of the most common Ink Recognizer SDK tasks, including:
- Implement InkPoint and InkStroke classes
- Convert stroke unit from pixel to mm
- Set language recognition locale
- Indexing a key word from recognition results
- Set application kind if user know expected type of ink content
Troubleshooting
General
Ink Recognizer clients raise exceptions defined in azure-core. For example, if you try to reach an invalid URL, InkRecognizerClient raises ResourceNotFoundError:
from azure.core.exceptions import ResourceNotFoundError
client = InkRecognizerClient("invalid_url", credential)
try:
client.recognize_ink(ink_strokes)
except ResourceNotFoundError as e:
print(e.message)
Logging
Network trace logging is disabled by default for this library. When enabled, HTTP requests will be logged at DEBUG level using the logging library. You can configure logging to print debugging information to stdout or write it to a file:
import sys
import logging
# Create a logger for the 'azure' SDK
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Configure a console output
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
# Configure a file output
file_handler = logging.FileHandler(filename)
logger.addHandler(file_handler)
# Enable network trace logging. Each HTTP request will be logged at DEBUG level.
client = InkRecognizerClient(url=url, credential=credential, logging_enable=True)
Next steps
Please find interactive inking samples at tkinter sample and wxpython sample.
Additional documentation
For more extensive documentation on the Ink Recognizer Service, see the Ink Recognizer Service Documentation.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
History
Version 1.0.0b1
Initial version for preview
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file azure-cognitiveservices-inkrecognizer-1.0.0b1.zip
.
File metadata
- Download URL: azure-cognitiveservices-inkrecognizer-1.0.0b1.zip
- Upload date:
- Size: 30.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf3d7f9e0326dc59971e9aa06247f0fec0d43e099f67521c5663200d0bcb9a27 |
|
MD5 | f984c1320ae9cf7cd7b7e849e84cd96b |
|
BLAKE2b-256 | 17275a87a11cb7055ba916591ea2e28a662746bea7d8468031abd4a26c8e3a44 |
File details
Details for the file azure_cognitiveservices_inkrecognizer-1.0.0b1-py2.py3-none-any.whl
.
File metadata
- Download URL: azure_cognitiveservices_inkrecognizer-1.0.0b1-py2.py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db7993a89549276fa0dd3f6e2f2655803a8459b8b4ee4696d540d0e91d8f577 |
|
MD5 | 8482909832fbbdee6c86cc763f9c8dde |
|
BLAKE2b-256 | ac048ca85624cfd2a1680bd78073038e0877f03110f456da9baf7f2bfb34aa33 |