Skip to content

Commit

Permalink
[AutoPR cognitiveservices/data-plane/ComputerVision] [Computer Vision…
Browse files Browse the repository at this point in the history
…] Add read to CV OCR API. (#4473)

* Generated from cbcb8cc3c280c9725bca0f4e0feb4bfc57b677ec

Add read to OCR API.

* Packaging update of azure-cognitiveservices-vision-computervision

* Generated from 51742b3e212c2e900ed5c24f7c351fa7f896d25e

Mark asyncBatchAnalyze as long running operation.

* Generated from b047a112a2c4cddaa54605d5de6a7bc3faab38c7

Update page property.
  • Loading branch information
AutorestCI authored Mar 5, 2019
1 parent 798f589 commit b3bbca7
Show file tree
Hide file tree
Showing 16 changed files with 447 additions and 84 deletions.
1 change: 1 addition & 0 deletions azure-cognitiveservices-vision-computervision/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
recursive-include tests *.py *.yaml
include *.rst
include azure/__init__.py
include azure/cognitiveservices/__init__.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,125 @@ def get_text_operation_result(
return deserialized
get_text_operation_result.metadata = {'url': '/textOperations/{operationId}'}

def batch_read_file(
self, url, mode, custom_headers=None, raw=False, **operation_config):
"""Use this interface to get the result of a Read operation, employing the
state-of-the-art Optical Character Recognition (OCR) algorithms
optimized for text-heavy documents. When you use the Read File
interface, the response contains a field called "Operation-Location".
The "Operation-Location" field contains the URL that you must use for
your "Read Operation Result" operation to access OCR results.​.
:param mode: Type of text to recognize. Possible values include:
'Handwritten', 'Printed'
:type mode: str or
~azure.cognitiveservices.vision.computervision.models.TextRecognitionMode
:param url: Publicly reachable URL of an image.
:type url: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: None or ClientRawResponse if raw=true
:rtype: None or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`ComputerVisionErrorException<azure.cognitiveservices.vision.computervision.models.ComputerVisionErrorException>`
"""
image_url = models.ImageUrl(url=url)

# Construct URL
url = self.batch_read_file.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['mode'] = self._serialize.query("mode", mode, 'TextRecognitionMode')

# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if custom_headers:
header_parameters.update(custom_headers)

# Construct body
body_content = self._serialize.body(image_url, 'ImageUrl')

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [202]:
raise models.ComputerVisionErrorException(self._deserialize, response)

if raw:
client_raw_response = ClientRawResponse(None, response)
client_raw_response.add_headers({
'Operation-Location': 'str',
})
return client_raw_response
batch_read_file.metadata = {'url': '/read/core/asyncBatchAnalyze'}

def get_read_operation_result(
self, operation_id, custom_headers=None, raw=False, **operation_config):
"""This interface is used for getting OCR results of Read operation. The
URL to this interface should be retrieved from "Operation-Location"
field returned from Batch Read File interface.
:param operation_id: Id of read operation returned in the response of
the "Batch Read File" interface.
:type operation_id: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: ReadOperationResult or ClientRawResponse if raw=true
:rtype:
~azure.cognitiveservices.vision.computervision.models.ReadOperationResult
or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`ComputerVisionErrorException<azure.cognitiveservices.vision.computervision.models.ComputerVisionErrorException>`
"""
# Construct URL
url = self.get_read_operation_result.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True),
'operationId': self._serialize.url("operation_id", operation_id, 'str')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
if custom_headers:
header_parameters.update(custom_headers)

# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
raise models.ComputerVisionErrorException(self._deserialize, response)

deserialized = None

if response.status_code == 200:
deserialized = self._deserialize('ReadOperationResult', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
get_read_operation_result.metadata = {'url': '/read/operations/{operationId}'}

def analyze_image_in_stream(
self, image, visual_features=None, details=None, language="en", custom_headers=None, raw=False, callback=None, **operation_config):
"""This operation extracts a rich set of visual features based on the
Expand Down Expand Up @@ -1606,3 +1725,69 @@ def recognize_text_in_stream(
})
return client_raw_response
recognize_text_in_stream.metadata = {'url': '/recognizeText'}

def batch_read_file_in_stream(
self, image, mode, custom_headers=None, raw=False, callback=None, **operation_config):
"""Use this interface to get the result of a Read Document operation,
employing the state-of-the-art Optical Character Recognition (OCR)
algorithms optimized for text-heavy documents. When you use the Read
Document interface, the response contains a field called
"Operation-Location". The "Operation-Location" field contains the URL
that you must use for your "Get Read Result operation" to access OCR
results.​.
:param image: An image stream.
:type image: Generator
:param mode: Type of text to recognize. Possible values include:
'Handwritten', 'Printed'
:type mode: str or
~azure.cognitiveservices.vision.computervision.models.TextRecognitionMode
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param callback: When specified, will be called with each chunk of
data that is streamed. The callback should take two arguments, the
bytes of the current chunk of data and the response object. If the
data is uploading, response will be None.
:type callback: Callable[Bytes, response=None]
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: None or ClientRawResponse if raw=true
:rtype: None or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`ComputerVisionErrorException<azure.cognitiveservices.vision.computervision.models.ComputerVisionErrorException>`
"""
# Construct URL
url = self.batch_read_file_in_stream.metadata['url']
path_format_arguments = {
'Endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['mode'] = self._serialize.query("mode", mode, 'TextRecognitionMode')

# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/octet-stream'
if custom_headers:
header_parameters.update(custom_headers)

# Construct body
body_content = self._client.stream_upload(image, callback)

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters, body_content)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [202]:
raise models.ComputerVisionErrorException(self._deserialize, response)

if raw:
client_raw_response = ClientRawResponse(None, response)
client_raw_response.add_headers({
'Operation-Location': 'str',
})
return client_raw_response
batch_read_file_in_stream.metadata = {'url': '/read/core/asyncBatchAnalyze'}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
from .celebrity_results_py3 import CelebrityResults
from .word_py3 import Word
from .line_py3 import Line
from .recognition_result_py3 import RecognitionResult
from .text_recognition_result_py3 import TextRecognitionResult
from .text_operation_result_py3 import TextOperationResult
from .read_operation_result_py3 import ReadOperationResult
except (SyntaxError, ImportError):
from .face_rectangle import FaceRectangle
from .celebrities_model import CelebritiesModel
Expand Down Expand Up @@ -83,11 +84,14 @@
from .celebrity_results import CelebrityResults
from .word import Word
from .line import Line
from .recognition_result import RecognitionResult
from .text_recognition_result import TextRecognitionResult
from .text_operation_result import TextOperationResult
from .read_operation_result import ReadOperationResult
from .computer_vision_client_enums import (
Gender,
TextOperationStatusCodes,
TextRecognitionResultDimensionUnit,
TextRecognitionResultConfidenceClass,
OcrLanguages,
VisualFeatureTypes,
TextRecognitionMode,
Expand Down Expand Up @@ -130,10 +134,13 @@
'CelebrityResults',
'Word',
'Line',
'RecognitionResult',
'TextRecognitionResult',
'TextOperationResult',
'ReadOperationResult',
'Gender',
'TextOperationStatusCodes',
'TextRecognitionResultDimensionUnit',
'TextRecognitionResultConfidenceClass',
'OcrLanguages',
'VisualFeatureTypes',
'TextRecognitionMode',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ class TextOperationStatusCodes(str, Enum):
succeeded = "Succeeded"


class TextRecognitionResultDimensionUnit(str, Enum):

pixel = "pixel"
inch = "inch"


class TextRecognitionResultConfidenceClass(str, Enum):

high = "High"
low = "Low"


class OcrLanguages(str, Enum):

unk = "unk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@


class Line(Model):
"""Line.
"""Json object representing a recognized text line.
:param bounding_box:
:param bounding_box: Bounding box of a recognized line.
:type bounding_box: list[int]
:param text:
:param text: The text content of the line.
:type text: str
:param words:
:param words: List of words in the text line.
:type words:
list[~azure.cognitiveservices.vision.computervision.models.Word]
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@


class Line(Model):
"""Line.
"""Json object representing a recognized text line.
:param bounding_box:
:param bounding_box: Bounding box of a recognized line.
:type bounding_box: list[int]
:param text:
:param text: The text content of the line.
:type text: str
:param words:
:param words: List of words in the text line.
:type words:
list[~azure.cognitiveservices.vision.computervision.models.Word]
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model


class ReadOperationResult(Model):
"""OCR result of the read operation.
:param status: Status of the read operation. Possible values include: 'Not
Started', 'Running', 'Failed', 'Succeeded'
:type status: str or
~azure.cognitiveservices.vision.computervision.models.TextOperationStatusCodes
:param recognition_results: A array of text recognition result of the read
operation.
:type recognition_results:
list[~azure.cognitiveservices.vision.computervision.models.TextRecognitionResult]
"""

_attribute_map = {
'status': {'key': 'status', 'type': 'TextOperationStatusCodes'},
'recognition_results': {'key': 'recognitionResults', 'type': '[TextRecognitionResult]'},
}

def __init__(self, **kwargs):
super(ReadOperationResult, self).__init__(**kwargs)
self.status = kwargs.get('status', None)
self.recognition_results = kwargs.get('recognition_results', None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model


class ReadOperationResult(Model):
"""OCR result of the read operation.
:param status: Status of the read operation. Possible values include: 'Not
Started', 'Running', 'Failed', 'Succeeded'
:type status: str or
~azure.cognitiveservices.vision.computervision.models.TextOperationStatusCodes
:param recognition_results: A array of text recognition result of the read
operation.
:type recognition_results:
list[~azure.cognitiveservices.vision.computervision.models.TextRecognitionResult]
"""

_attribute_map = {
'status': {'key': 'status', 'type': 'TextOperationStatusCodes'},
'recognition_results': {'key': 'recognitionResults', 'type': '[TextRecognitionResult]'},
}

def __init__(self, *, status=None, recognition_results=None, **kwargs) -> None:
super(ReadOperationResult, self).__init__(**kwargs)
self.status = status
self.recognition_results = recognition_results
Loading

0 comments on commit b3bbca7

Please sign in to comment.