azure.cognitiveservices.inkrecognizer package¶
Submodules¶
Module contents¶
-
class
azure.cognitiveservices.inkrecognizer.
ApplicationKind
[source]¶ Bases:
enum.Enum
The ApplicationKind enum allows an application to identify its domain (when it has one). Specifying a domain allows the application to inform the service of its contents. This can facilitate faster processing as the service will skip some classification steps. Applications that don’t have a specific domain can simply specify ApplicationKind.MIXED, which is the default.
-
DRAWING
= 'drawing'¶ The application can only have drawing strokes.
-
MIXED
= 'mixed'¶ The application can have strokes of different kinds.
-
WRITING
= 'writing'¶ The application can only have writing strokes.
-
-
class
azure.cognitiveservices.inkrecognizer.
InkPointUnit
[source]¶ Bases:
enum.Enum
The length unit passes to InkPoint. Default is InkPointUnit.MM.
-
CM
= 'cm'¶
-
INCH
= 'in'¶
-
MM
= 'mm'¶
-
-
class
azure.cognitiveservices.inkrecognizer.
InkRecognitionUnitKind
[source]¶ Bases:
enum.Enum
The InkRecognitionUnitKind has all the different categories of recognition units available from the service.
-
INK_BULLET
= 'inkBullet'¶ A bullet on a line of text. The bullet can be associated with more than one line.
-
INK_DRAWING
= 'inkDrawing'¶ A drawing which may have alternates, or an alternate of a drawing.
-
INK_WORD
= 'inkWord'¶ A word which may have alternates, or an alternate of a word.
-
LINE
= 'line'¶ A line, that contains a list of words, and may contain a bullet if it inside a list.
-
LIST_ITEM
= 'listItem'¶ One item of a list. It has only a line as its child, where a bullet should at the begining of that line.
-
PARAGRAPH
= 'paragraph'¶ A paragraph that contains multiple lines and / or lists.
-
UNKNOWN
= 'unknown'¶ Some stroke can’t recognized by Ink Recognizer service.
-
WRITING_REGION
= 'writingRegion'¶ A writing region is a part of the writing surface that contains words.
-
-
class
azure.cognitiveservices.inkrecognizer.
ShapeKind
[source]¶ Bases:
enum.Enum
The Shape enum represents different shapes that can be reported by the ink recognizer service. Any unrecognized shpae will be reported as ShapeKind.DRAWING.
-
BLOCK_ARROW
= 'blockArrow'¶
-
CIRCLE
= 'circle'¶
-
CLOUD
= 'cloud'¶
-
CURVE
= 'curve'¶
-
DIAMOND
= 'diamond'¶
-
DRAWING
= 'drawing'¶
-
ELLIPSE
= 'ellipse'¶
-
EQUILATERAL_TRIANGLE
= 'equilateralTriangle'¶
-
HEART
= 'heart'¶
-
HEXAGON
= 'hexagon'¶
-
ISOSCELES_TRIANGLE
= 'isoscelesTriangle'¶
-
LINE
= 'line'¶
-
PARALLELOGRAM
= 'parallelogram'¶
-
PENTAGON
= 'pentagon'¶
-
POLYLINE
= 'polyline'¶
-
QUADRILATERAL
= 'quadrilateral'¶
-
RECTANGLE
= 'rectangle'¶
-
RIGHT_TRIANGLE
= 'rightTriangle'¶
-
SQUARE
= 'square'¶
-
STAR_CROSSED
= 'starCrossed'¶
-
STAR_SIMPLE
= 'starSimple'¶
-
TRAPEZOID
= 'trapezoid'¶
-
TRIANGLE
= 'triangle'¶
-
-
class
azure.cognitiveservices.inkrecognizer.
InkStrokeKind
[source]¶ Bases:
enum.Enum
The InkStrokeKind enum represents the class a stroke belongs too. The user of the Ink recognizer service is expected to set this value when it is known with absolute certainly. The default value is InkStrokeKind.UNKNOWN.
-
DRAWING
= 'inkDrawing'¶ Specify the stroke is a drawing stroke.
-
UNKNOWN
= 'unknown'¶ Use default stroke kind in ApplicationKind. If ApplicationKind set to Unknown, server will recognize the stroke kind.
-
WRITING
= 'inkWriting'¶ Specify the stroke is a writing stroke.
-
-
class
azure.cognitiveservices.inkrecognizer.
ServiceVersion
[source]¶ Bases:
enum.Enum
Target version of Ink Recognizer service.
-
PREVIEW
= 'v1.0-preview'¶ Preview service version.
-
-
class
azure.cognitiveservices.inkrecognizer.
InkRecognizerClient
(url, credential, **kwargs)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._client._InkRecognizerClientBase
The InkRecognizerClient communicates with the service using default configuration settings or settings provided by the caller (which override the default settings). Communication with the service is blocking/synchronous.
- Parameters
url (str) – target url of the Ink Recognizer service.
credential (TokenCredential) – An available Azure Active
Directory credential for Ink Recognition Service.
Key word arguments include Ink Recognizer specific arguments, azure service common arguments and azure pipline policies.
Ink Recognizer specific arguments:
- Parameters
service_version (ServiceVersion) – Version of Ink Recognizer Service.
Default is ServiceVersion.Preview.
- Parameters
application_kind (ApplicationKind) – Inform Ink Recognizer Service of
contents of the application. This can facilitate faster processing as the service will skip some classification steps. Default is ApplicationKind.MIXED.
- Parameters
ink_point_unit (InkPointUnit) – unit of the x and y axis coordinates
for each InkPoint. Default is InkPointUnit.MM.
- Parameters
language (str) – Language (IETF BCP-47) of strokes, can be overwritten
by stroke-specific language. Default is “en-US”.
- Parameters
unit_multiple (float) – multiplier for unit. Each value in InkPoint
will be multiplied by this value on server side. Default is 1.0.
Azure service common arguments:
- Parameters
transport (HttpTransport) – transport
instance for the client. Default is RequestsTransport().
- Parameters
(headers, deserialized_response) if the http status is 200.
Azure pipeline policies: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/docs/configuration.md
-
recognize_ink
(ink_stroke_list, **kwargs)[source]¶ Synchronously sends data to the service and returns a tree structure containing all the recognition units from Ink Recognizer Service.
- Parameters
ink_stroke_list (Iterable[IInkStroke]) – an iterable that contanins
stroke instances.
Key word arguments include Ink Recognizer specific arguments, azure service common arguments and azure pipline policies.
Ink Recognizer specific arguments:
- Parameters
service_version (ServiceVersion) – Version of Ink Recognizer Service.
Default is ServiceVersion.Preview.
- Parameters
application_kind (ApplicationKind) – Inform Ink Recognizer Service of
contents of the application. This can facilitate faster processing as the service will skip some classification steps. Default is ApplicationKind.MIXED.
- Parameters
ink_point_unit (InkPointUnit) – unit of the x and y axis coordinates
for each InkPoint. Default is InkPointUnit.MM.
- Parameters
language (str) – Language (IETF BCP-47) of strokes, can be overwritten
by stroke-specific language. Default is “en-US”.
- Parameters
unit_multiple (float) – multiplier for unit. Each value in InkPoint
will be multiplied by this value on server side. Default is 1.0.
Azure service common arguments:
- Parameters
(headers, deserialized_response) if the http status is 200.
Azure pipeline policies: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/docs/configuration.md
- Return type
Exceptions:
- Raises
ServerResponseError – Unexpected Server response that can’t be parsed by client.
ResourceNotFoundError – Indicates URL is invalid.
ClientAuthenticationError – Authentication issue.
HttpResponseError – Unclassified error.
-
class
azure.cognitiveservices.inkrecognizer.
IInkPoint
[source]¶ Bases:
abc.ABC
Interface for an InkPoint. An InkPoint represents a single position on the path of an ink stroke. Clients of the Ink Recognizer Service can implement this interface to store points in InkStroke instances.
-
abstract property
x
¶ X-axis coordinate of the point. Should be float.
-
abstract property
y
¶ Y-axis coordinate of the point. Should be float.
-
abstract property
-
class
azure.cognitiveservices.inkrecognizer.
IInkStroke
[source]¶ Bases:
abc.ABC
Interface of InkStroke. An InkStroke represents an ink stroke: a collection of IInkPoints from the time user places his writing instrument on the writing surface until the the instrument is lifted. Clients of the Ink Recognizer Service can implement this interface. An InkRecognizerClient instance accepts an iterable of IInkStroke instances, translate them to JSON and deliver to the Ink Recognizer Service.
-
abstract property
id
¶ An integer stroke id. The numerical order (ascending) of stroke ids indicates the order of strokes. For example, there are three strokes s_0, s_1, s_2, where s_0.id = 0, s_1.id = 1, s_2.id = 2. No matter what order they are sent into InkRecognizerClient, they will be re-ordered as (s_0, s_1, s_2) when doing ink recognition.
- Return type
-
abstract property
kind
¶ InkStrokeKind of the stroke.
- Return type
-
abstract property
-
class
azure.cognitiveservices.inkrecognizer.
Point
(x, y)[source]¶ Bases:
object
The Point class, unlike the IInkPoint interface, represents a single geometric position on a plane. The point is used to specify the center point of the bounding rectangle of a recognition unit and the key points of a well-formed recognized shape, i.e a beautified shape from Ink Recognizer Service based on the ink shape sent to it.
-
property
x
¶ X-axis coordinate of the point.
-
property
y
¶ X-axis coordinate of the point.
-
property
-
class
azure.cognitiveservices.inkrecognizer.
Rectangle
(rect_dict)[source]¶ Bases:
object
The class represents a rectangle used to identify the boundary of the strokes in a recognition unit.
-
property
height
¶ Height of the rectangle.
-
property
width
¶ Width of the rectangle.
-
property
x
¶ X-axis coordinate of upperleft vertex.
-
property
y
¶ Y-axis coordinate of upperleft vertex.
-
property
-
class
azure.cognitiveservices.inkrecognizer.
InkRecognitionUnit
(json_object)[source]¶ Bases:
object
An InkRecognitionUnit instance represents a single entity recognized by the Ink Recognizer Service.
-
property
bounding_box
¶ The bounding box is the rectangular area that contains all the strokes in a recognition unit.
- Return type
-
property
children
¶ The children of a recognition unit represent the units contained in a container unit. An example is the relationship between a line and the words on the line. The children of the line is a list of words. “Leaf” units like words which have no children will always return an empty list.
- Return type
List[InkRecognitionUnit]
-
property
id
¶ Unique identifier for the recognition unit.
rtype: int
-
property
kind
¶ The kind of the current recognition unit.
- Return type
-
property
parent
¶ The parent of a recognition unit represent the unit containing this unit. An example is the relationship between a line and the words on the line. The line is the parent of the words. The top level recognition unit will return None as the parent.
- Return type
-
property
rotated_bounding_box
¶ The rotated bounding box is the oriented rectangular area that contains all the strokes in a recognition unit. Its shape is influenced by the detected orientation of the ink in the recognition unit. It is represented by a list of Points which are the vertices of the rect, clockwise.
- Return type
List[Point]
-
property
-
class
azure.cognitiveservices.inkrecognizer.
InkBullet
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
An InkBullet instance represents the collection of one or more ink strokes that were recognized as a bullet point on a line.
-
class
azure.cognitiveservices.inkrecognizer.
InkDrawing
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
An InkDrawing instance represents the collection of one or more ink strokes that were recognized as a drawing/shape.
-
property
alternates
¶ A list of alternate InkDrawings when the confidence isn’t 1. If this InkDrawing is an alternate, returns None.
- Return type
List[InkDrawing] or None
-
property
center
¶ The center point of the bounding box of the recognition unit as Point.
- Return type
-
property
confidence
¶ A number between 0 and 1 which indicates the confidence level in the result.
- Return type
-
property
points
¶ A list of Point instances that represent points that are relevant to the type of recognition unit. For example, for a leaf node of inkDrawing kind that represents a triangle, points would include the x,y coordinates of the vertices of the recognized triangle. The points represent the coordinates of points used to create the perfectly drawn shape that is closest to the original input. They may not exactly match.
- Return type
List[Point]
-
property
recognized_shape
¶ The ShapeKind enum representing the geometric shape that was recognized. If the drawing isn’t one of the known geometric shapes, an ShapeKind.DRAWING is returned.
- Return type
-
property
-
class
azure.cognitiveservices.inkrecognizer.
Line
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
A Line instance represents the collection of one or more ink strokes that were recognized as a line.
-
property
bullet
¶ If the line has a bullet, return it as InkBullet. Otherwise, return None. One line can have at most one bullet.
-
property
recognized_text
¶ The recognized string of the line. If the words in the line are not recognized, an empty string is returned.
- Return type
-
property
-
class
azure.cognitiveservices.inkrecognizer.
Paragraph
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
A Paragraph instance represents the collection of one or more ink strokes that were recognized as a paragraph.
-
property
list_items
¶ All the ListItems in the paragraph.
-
property
-
class
azure.cognitiveservices.inkrecognizer.
InkWord
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
An InkWord instance represents the collection of one or more ink strokes that were recognized as a word.
-
class
azure.cognitiveservices.inkrecognizer.
WritingRegion
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
A WritingRegion instance represents a certain part of a writing surface that the user has written at least one word on. WritingRegions are the top-level writing objects under an InkRecognitionRoot.
-
class
azure.cognitiveservices.inkrecognizer.
ListItem
(json_object)[source]¶ Bases:
azure.cognitiveservices.inkrecognizer._models.InkRecognitionUnit
A ListItem instance represents an item of a list. It has a line which has a bullet at the beginning of it. The list that this ListItem belongs to is not given by Ink Recognizer Service.
-
class
azure.cognitiveservices.inkrecognizer.
InkRecognitionRoot
(units)[source]¶ Bases:
object
An InkRecognitionRoot instance is the return type from the recognize_ink method in InkRecognizerClient. It is the root of the of recognition unit tree. It also contains the HTTP request status code of the recognition request. WritingRegions and Shapes are the only top-level objects under an InkRecognitionRoot.
-
find_word
(word)[source]¶ Returns all Inkwords returned by the Ink Recognizer Service whose recognized text is exactly the same as the given string. This is case insensitive.
-
property
ink_bullets
¶ The list of all InkBullets found in the tree returned by the Ink Recognizer Service.
- Return type
List[InkBullet]
-
property
ink_drawings
¶ The list of all InkDrawing found in the tree returned by the Ink Recognizer Service.
- Return type
List[InkDrawing]
-
property
ink_words
¶ The list of all InkWord found in the tree returned by the Ink Recognizer Service.
- Return type
List[InkWord]
-
property
lines
¶ The list of all Lines found in the tree returned by the Ink Recognizer Service.
- Return type
List[Line]
-
property
list_items
¶ The list of all ListItems found in the tree returned by the Ink Recognizer Service.
- Return type
List[ListItem]
-
property
paragraphs
¶ The list of all Paragraphs found in the tree returned by the Ink Recognizer Service.
- Return type
List[Paragraph]
-
property
writing_regions
¶ The list of all WritingRegions found in the tree returned by the Ink Recognizer Service.
- Return type
List[WritingRegion]
-