Package: azure-cognitiveservices-inkrecognizer
Azure Ink Recognizer client library for PythonAzure 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 ServiceConvert collections of ink strokes into HTTP requestsParse HTTP response into ink recognition unitsSource code|Package (PyPi)|API reference documentation|Product documentation|SamplesGetting startedInstall the packageInstall the Azure Cosmos DB client library for Python withpip:pipinstallazure-cognitiveservices-inkrecognizerPrerequisites: You must have anAzure subscription. You must havePython 2.7orPython 3.5.3+to use this package. Asynchronous features supports Python 3.5.3+ only.Get URLPlease find the URL atInk Recognizer Rest API documentationGet credentialsPlease follow the instructions onInk Recognizer.Key conceptsImplement ink strokeIf you don't have any pre-defined ink point or ink stroke classes, you can either follow theInk Stroke Interfacesto 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.fromazure.cognitiveservices.inkrecognizerimportInkStrokeKindInkPoint=namedtuple("InkPoint","x y")classInkStroke():def__init__(self,ink_stroke_id,ink_points,stroke_kind=InkStrokeKind.UNKNOWN,stroke_language=""):self.id=ink_stroke_idself.points=ink_pointsself.kind=stroke_kindself.language=stroke_languageYou can then create a list (or any iterable object) of ink strokes for recognition.Create a clientOnce you got the url for ink recognizer service and an Azure credential instance, you can create an InkRecognizerClientfromazure.cognitiveservices.inkrecognizerimportInkRecognizerClientclient=InkRecognizerClient(url,api_key)# api_key is your key as stringOr use Async version (Python 3.5.3+ only)fromazure.cognitiveservices.inkrecognizer.aioimportInkRecognizerClientclient=InkRecognizerClient(url,api_key)# api_key is your key as stringSend a requestYou can then send stroke list to Ink Recognizer Service and get the root of all ink recognition results.# Sync versionrecognition_root=client.recognize_ink(ink_stroke_list)# Async versionrecognition_root=awaitclient.recognize_ink(ink_stroke_list)Get recognition units from resultsYou can get all the recognition units either by InkRecognitionUnitKind or by hierarchy, then visit support properties of the units.API reference documentationlines=recognition_root.linesforlineinlines:foo_show_bounding_box(line.bounding_box)forwordinline.words:print(word.recognized_text)ExamplesTheSamplesprovide several code snippets covering some of the most common Ink Recognizer SDK tasks, including:Implement InkPoint and InkStroke classesConvert stroke unit from pixel to mmSet language recognition localeIndexing a key word from recognition resultsSet application kind if user know expected type of ink contentTroubleshootingGeneralInk Recognizer clients raise exceptions defined in azure-core. For example, if you try to reach an invalid URL, InkRecognizerClient raises ResourceNotFoundError:fromazure.core.exceptionsimportResourceNotFoundErrorclient=InkRecognizerClient("invalid_url",credential)try:client.recognize_ink(ink_strokes)exceptResourceNotFoundErrorase:print(e.message)LoggingNetwork 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:importsysimportlogging# Create a logger for the 'azure' SDKlogger=logging.getLogger(__name__)logger.setLevel(logging.DEBUG)# Configure a console outputhandler=logging.StreamHandler(stream=sys.stdout)logger.addHandler(handler)# Configure a file outputfile_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 stepsPlease find interactive inking samples attkinter sampleandwxpython sample.Additional documentationFor more extensive documentation on the Ink Recognizer Service, see theInk Recognizer Service Documentation.ContributingThis 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, visithttps://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 theMicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor
contactopencode@microsoft.comwith any additional questions or comments.HistoryVersion 1.0.0b1Initial version for preview