Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/storage-p…
Browse files Browse the repository at this point in the history
…review4
  • Loading branch information
lmazuel committed Oct 2, 2019
2 parents 564722b + 2ed938f commit 1979c89
Show file tree
Hide file tree
Showing 84 changed files with 7,196 additions and 2,012 deletions.
4 changes: 4 additions & 0 deletions eng/pipelines/templates/jobs/archetype-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ parameters:
OSName: 'Windows'
OSVmImage: 'windows-2019'
PythonVersion: '2.7'
Linux_PyPy3:
OSName: 'Linux'
OSVmImage: 'ubuntu-16.04'
PythonVersion: 'pypy3'

jobs:
- job: 'Test'
Expand Down
3 changes: 2 additions & 1 deletion eng/tox/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ deps =
pytest-custom_exit_code
pytest-cov
pytest-xdist
pytest-asyncio; python_version >= '3.5'
coverage

[testenv]
Expand Down Expand Up @@ -77,4 +78,4 @@ deps =
commands =
pytest \
{posargs} \
{toxinidir}
{toxinidir}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# History

## Version 1.0.0b1

Initial version for preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include *.md
include azure/__init__.py
include azure/cognitiveservices/__init__.py
181 changes: 181 additions & 0 deletions sdk/cognitiveservices/azure-cognitiveservices-inkrecognizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# 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][source_code] | [Package (PyPi)][pypi] | [API reference documentation][ref_inkrecognizer_sdk] | [Product documentation][ink_recognizer_docs] | [Samples][samples]

## Getting started

### Install the package

Install the Azure Cosmos DB client library for Python with [pip][pip]:

```Bash
pip install azure-cognitiveservices-inkrecognizer
```

**Prerequisites**: You must have an [Azure subscription][azure_sub]. You must have [Python 2.7][python] or [Python 3.5.3+][python] to use this package. Asynchronous features supports Python 3.5.3+ only.

#### Get URL

Please find the URL at [Ink Recognizer Rest API documentation][ink_recognizer_restapi_docs]

#### Get credentials

Please follow the instructions on [Ink Recognizer][azure_ink_recognizer_home].

## 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][ref_ink_stroke_file] 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.

```Python
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

```Python
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)

```Python
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.

```Python
# 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][ref_inkrecognizer_sdk]

```Python
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][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:

```Python
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:

```Python
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](https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/tree/master/samples/vision/inkrecognizer_tkinter_sample.py) and [wxpython sample](https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/tree/master/samples/vision/inkrecognizer_tkinter_sample.py).

### Additional documentation

For more extensive documentation on the Ink Recognizer Service, see the [Ink Recognizer Service Documentation][ink_recognizer_docs].

## 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](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

<!-- LINKS -->
[azure_sub]: https://azure.microsoft.com/free/
[ink_recognizer_docs]: https://docs.microsoft.com/azure/cognitive-services/ink-recognizer/
[ink_recognizer_restapi_docs]: https://docs.microsoft.com/rest/api/cognitiveservices/inkrecognizer/inkrecognizer/recognize
[azure_ink_recognizer_home]: https://azure.microsoft.com/services/cognitive-services/ink-recognizer/
[pip]: https://pypi.org/project/pip/
[pypi]: https://pypi.org/project/azure-cosmos/
[python]: https://www.python.org/downloads/
[ref_inkrecognizer_sdk]: https://
[ref_ink_stroke_file]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cognitiveservices/azure-cognitiveservices-inkrecognizer/azure/cognitiveservices/inkrecognizer/_ink_stroke.py
[ref_inkrecognizer_client]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cognitiveservices/azure-cognitiveservices-inkrecognizer/azure/cognitiveservices/inkrecognizer/_client.py
[samples]: https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/tree/master/samples/vision
[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cognitiveservices/azure-cognitiveservices-inkrecognizer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#--------------------------------------------------------------------------

from ._enums import (
ApplicationKind,
InkPointUnit,
InkRecognitionUnitKind,
ShapeKind,
InkStrokeKind,
ServiceVersion
)
from ._client import InkRecognizerClient
from ._ink_stroke import (
IInkPoint,
IInkStroke
)
from ._models import (
Point,
Rectangle,
InkRecognitionUnit,
InkBullet,
InkDrawing,
Line,
Paragraph,
InkWord,
WritingRegion,
ListItem,
InkRecognitionRoot
)
from ._version import VERSION

__all__ = [
# enums
"ApplicationKind",
"InkPointUnit",
"InkRecognitionUnitKind",
"ShapeKind",
"InkStrokeKind",
"ServiceVersion",
# client
"InkRecognizerClient",
# interfaces
"IInkPoint",
"IInkStroke",
# models
"Point",
"Rectangle",
"InkRecognitionUnit",
"InkBullet",
"InkDrawing",
"Line",
"Paragraph",
"InkWord",
"WritingRegion",
"ListItem",
"InkRecognitionRoot"
]

__version__ = VERSION
Loading

0 comments on commit 1979c89

Please sign in to comment.