Skip to content

Commit 370ed8a

Browse files
committed
returning mgmt-batch to what it should be
1 parent f03e0ee commit 370ed8a

File tree

1 file changed

+18
-318
lines changed

1 file changed

+18
-318
lines changed

sdk/batch/azure-mgmt-batch/README.md

+18-318
Original file line numberDiff line numberDiff line change
@@ -1,329 +1,29 @@
1-
# Azure Cognitive Services Computer Vision SDK for Python
1+
## Microsoft Azure SDK for Python
22

3-
The Computer Vision service provides developers with access to advanced algorithms for processing images and returning information. Computer Vision algorithms analyze the content of an image in different ways, depending on the visual features you're interested in.
3+
This is the Microsoft Azure Batch Management Client Library.
44

5-
You can use Computer Vision in your application to:
5+
Azure Resource Manager (ARM) is the next generation of management APIs
6+
that replace the old Azure Service Management (ASM).
67

7-
- Analyze images for insight
8-
- Extract text from images
9-
- Generate thumbnails
8+
This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7.
109

11-
Looking for more documentation?
10+
For the older Azure Service Management (ASM) libraries, see
11+
[azure-servicemanagement-legacy](https://pypi.python.org/pypi/azure-servicemanagement-legacy)
12+
library.
1213

13-
* [SDK reference documentation](https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision)
14-
* [Cognitive Services Computer Vision documentation](https://docs.microsoft.com/azure/cognitive-services/computer-vision/)
15-
16-
## Prerequisites
17-
18-
* Azure subscription - [Create a free account][azure_sub]
19-
* Azure [Computer Vision resource][computervision_resource]
20-
* [Python 3.6+][python]
21-
22-
If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command:
23-
24-
```Bash
25-
RES_REGION=westeurope
26-
RES_GROUP=<resourcegroup-name>
27-
ACCT_NAME=<computervision-account-name>
28-
29-
az cognitiveservices account create \
30-
--resource-group $RES_GROUP \
31-
--name $ACCT_NAME \
32-
--location $RES_REGION \
33-
--kind ComputerVision \
34-
--sku S1 \
35-
--yes
36-
```
37-
38-
## Installation
39-
40-
Install the Azure Cognitive Services Computer Vision SDK with [pip][pip], optionally within a [virtual environment][venv].
41-
42-
### Configure a virtual environment (optional)
43-
44-
Although not required, you can keep your base system and Azure SDK environments isolated from one another if you use a [virtual environment][virtualenv]. Execute the following commands to configure and then enter a virtual environment with [venv][venv], such as `cogsrv-vision-env`:
45-
46-
```Bash
47-
python3 -m venv cogsrv-vision-env
48-
source cogsrv-vision-env/bin/activate
49-
```
50-
51-
### Install the SDK
52-
53-
Install the Azure Cognitive Services Computer Vision SDK for Python [package][pypi_computervision] with [pip][pip]:
54-
55-
```Bash
56-
pip install azure-cognitiveservices-vision-computervision
57-
```
58-
59-
## Authentication
60-
61-
Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object.
62-
63-
Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient] client object.
64-
65-
### Get credentials
66-
67-
Use the [Azure CLI][cloud_shell] snippet below to populate two environment variables with the Computer Vision account **region** and one of its **keys** (you can also find these values in the [Azure portal][azure_portal]). The snippet is formatted for the Bash shell.
68-
69-
```Bash
70-
RES_GROUP=<resourcegroup-name>
71-
ACCT_NAME=<computervision-account-name>
72-
73-
export ACCOUNT_REGION=$(az cognitiveservices account show \
74-
--resource-group $RES_GROUP \
75-
--name $ACCT_NAME \
76-
--query location \
77-
--output tsv)
78-
79-
export ACCOUNT_KEY=$(az cognitiveservices account keys list \
80-
--resource-group $RES_GROUP \
81-
--name $ACCT_NAME \
82-
--query key1 \
83-
--output tsv)
84-
```
85-
86-
### Create client
87-
88-
Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionAPI][ref_computervisionclient] client object.
89-
90-
```Python
91-
from azure.cognitiveservices.vision.computervision import ComputerVisionAPI
92-
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
93-
from msrest.authentication import CognitiveServicesCredentials
94-
95-
import os
96-
region = os.environ['ACCOUNT_REGION']
97-
key = os.environ['ACCOUNT_KEY']
98-
99-
credentials = CognitiveServicesCredentials(key)
100-
client = ComputerVisionAPI(region, credentials)
101-
```
14+
For a more complete set of Azure libraries, see the
15+
[azure](https://pypi.python.org/pypi/azure) bundle package.
10216

10317
## Usage
10418

105-
Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client object, you can:
106-
107-
* Analyze an image: You can analyze an image for certain features such as faces, colors, tags.
108-
* Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image.
109-
* Get description of an image: Get a description of the image based on its subject domain.
110-
111-
For more information about this service, see [What is Computer Vision?][computervision_docs].
112-
113-
## Examples
114-
115-
The following sections provide several code snippets covering some of the most common Computer Vision tasks, including:
116-
117-
* [Analyze an image](#analyze-an-image)
118-
* [Get subject domain list](#get-subject-domain-list)
119-
* [Analyze an image by domain](#analyze-an-image-by-domain)
120-
* [Get text description of an image](#get-text-description-of-an-image)
121-
* [Get handwritten text from image](#get-text-from-image)
122-
* [Generate thumbnail](#generate-thumbnail)
123-
124-
### Analyze an image
125-
126-
You can analyze an image for certain features with [`analyze_image`][ref_computervisionclient_analyze_image]. Use the [`visual_features`][ref_computervision_model_visualfeatures] property to set the types of analysis to perform on the image. Common values are `VisualFeatureTypes.tags` and `VisualFeatureTypes.description`.
127-
128-
```Python
129-
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Broadway_and_Times_Square_by_night.jpg/450px-Broadway_and_Times_Square_by_night.jpg"
130-
131-
image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags])
132-
133-
for tag in image_analysis.tags:
134-
print(tag)
135-
```
136-
137-
### Get subject domain list
138-
139-
Review the subject domains used to analyze your image with [`list_models`][ref_computervisionclient_list_models]. These domain names are used when [analyzing an image by domain](#analyze-an-image-by-domain). An example of a domain is `landmarks`.
140-
141-
```Python
142-
models = client.list_models()
143-
144-
for x in models.models_property:
145-
print(x)
146-
```
147-
148-
### Analyze an image by domain
149-
150-
You can analyze an image by subject domain with [`analyze_image_by_domain`][ref_computervisionclient_analyze_image_by_domain]. Get the [list of supported subject domains](#get-subject-domain-list) in order to use the correct domain name.
151-
152-
```Python
153-
domain = "landmarks"
154-
url = "https://images.pexels.com/photos/338515/pexels-photo-338515.jpeg"
155-
language = "en"
156-
157-
analysis = client.analyze_image_by_domain(domain, url, language)
158-
159-
for landmark in analysis.result["landmarks"]:
160-
print(landmark["name"])
161-
print(landmark["confidence"])
162-
```
163-
164-
### Get text description of an image
165-
166-
You can get a language-based text description of an image with [`describe_image`][ref_computervisionclient_describe_image]. Request several descriptions with the `max_description` property if you are doing text analysis for keywords associated with the image. Examples of a text description for the following image include `a train crossing a bridge over a body of water`, `a large bridge over a body of water`, and `a train crossing a bridge over a large body of water`.
167-
168-
```Python
169-
domain = "landmarks"
170-
url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg"
171-
language = "en"
172-
max_descriptions = 3
173-
174-
analysis = client.describe_image(url, max_descriptions, language)
175-
176-
for caption in analysis.captions:
177-
print(caption.text)
178-
print(caption.confidence)
179-
```
180-
181-
### Get text from image
182-
183-
You can get any handwritten or printed text from an image. This requires two calls to the SDK: [`recognize_text`][ref_computervisionclient_recognize_text] and [`get_text_operation_result`][ref_computervisionclient_get_text_operation_result]. The call to recognize_text is asynchronous. In the results of the get_text_operation_result call, you need to check if the first call completed with [`TextOperationStatusCodes`][ref_computervision_model_textoperationstatuscodes] before extracting the text data. The results include the text as well as the bounding box coordinates for the text.
184-
185-
```Python
186-
# import models
187-
from azure.cognitiveservices.vision.computervision.models import TextRecognitionMode
188-
from azure.cognitiveservices.vision.computervision.models import TextOperationStatusCodes
189-
190-
url = "https://azurecomcdn.azureedge.net/cvt-1979217d3d0d31c5c87cbd991bccfee2d184b55eeb4081200012bdaf6a65601a/images/shared/cognitive-services-demos/read-text/read-1-thumbnail.png"
191-
mode = TextRecognitionMode.handwritten
192-
raw = True
193-
custom_headers = None
194-
numberOfCharsInOperationId = 36
195-
196-
# SDK call
197-
rawHttpResponse = client.recognize_text(url, mode, custom_headers, raw)
198-
199-
# Get ID from returned headers
200-
operationLocation = rawHttpResponse.headers["Operation-Location"]
201-
idLocation = len(operationLocation) - numberOfCharsInOperationId
202-
operationId = operationLocation[idLocation:]
203-
204-
# SDK call
205-
result = client.get_text_operation_result(operationId)
206-
207-
# Get data
208-
if result.status == TextOperationStatusCodes.succeeded:
209-
210-
for line in result.recognition_result.lines:
211-
print(line.text)
212-
print(line.bounding_box)
213-
```
214-
215-
### Generate thumbnail
216-
217-
You can generate a thumbnail (JPG) of an image with [`generate_thumbnail`][ref_computervisionclient_generate_thumbnail]. The thumbnail does not need to be in the same proportions as the original image.
218-
219-
This example uses the [Pillow][pypi_pillow] package to save the new thumbnail image locally.
220-
221-
```Python
222-
from PIL import Image
223-
import io
224-
225-
width = 50
226-
height = 50
227-
url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg"
228-
229-
thumbnail = client.generate_thumbnail(width, height, url)
230-
231-
for x in thumbnail:
232-
image = Image.open(io.BytesIO(x))
233-
234-
image.save('thumbnail.jpg')
235-
```
236-
237-
## Troubleshooting
238-
239-
### General
240-
241-
When you interact with the [ComputerVisionAPI][ref_computervisionclient] client object using the Python SDK, the [`ComputerVisionErrorException`][ref_computervision_computervisionerrorexception] class is used to return errors. Errors returned by the service correspond to the same HTTP status codes returned for REST API requests.
242-
243-
For example, if you try to analyze an image with an invalid key, a `401` error is returned. In the following snippet, the [error][ref_httpfailure] is handled gracefully by catching the exception and displaying additional information about the error.
244-
245-
```Python
246-
247-
domain = "landmarks"
248-
url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg"
249-
language = "en"
250-
max_descriptions = 3
251-
252-
try:
253-
analysis = client.describe_image(url, max_descriptions, language)
254-
255-
for caption in analysis.captions:
256-
print(caption.text)
257-
print(caption.confidence)
258-
except HTTPFailure as e:
259-
if e.status_code == 401:
260-
print("Error unauthorized. Make sure your key and region are correct.")
261-
else:
262-
raise
263-
```
264-
265-
### Handle transient errors with retries
266-
267-
While working with the [ComputerVisionAPI][ref_computervisionclient] client, you might encounter transient failures caused by [rate limits][computervision_request_units] enforced by the service, or other transient problems like network outages. For information about handling these types of failures, see [Retry pattern][azure_pattern_retry] in the Cloud Design Patterns guide, and the related [Circuit Breaker pattern][azure_pattern_circuit_breaker].
268-
269-
## Next steps
270-
271-
### More sample code
272-
273-
Several Computer Vision Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Computer Vision:
274-
275-
* [recognize_text][recognize-text]
276-
277-
### Additional documentation
278-
279-
For more extensive documentation on the Computer Vision service, see the [Azure Computer Vision documentation][computervision_docs] on docs.microsoft.com.
280-
281-
<!-- LINKS -->
282-
[pip]: https://pypi.org/project/pip/
283-
[python]: https://www.python.org/downloads/
284-
285-
[azure_cli]: https://docs.microsoft.com/cli/azure
286-
[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker
287-
[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry
288-
[azure_portal]: https://portal.azure.com
289-
[azure_sub]: https://azure.microsoft.com/free/
290-
291-
[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview
292-
293-
[venv]: https://docs.python.org/3/library/venv.html
294-
[virtualenv]: https://virtualenv.pypa.io
295-
296-
[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-cognitiveservices-vision-computervision
297-
298-
[pypi_computervision]:https://pypi.org/project/azure-cognitiveservices-vision-computervision/
299-
[pypi_pillow]:https://pypi.org/project/Pillow/
300-
301-
[ref_computervision_sdk]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision?view=azure-python
302-
[ref_computervision_computervisionerrorexception]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.computervisionerrorexception?view=azure-python
303-
[ref_httpfailure]: https://docs.microsoft.com/python/api/msrest/msrest.exceptions.httpoperationerror?view=azure-python
304-
305-
306-
[computervision_resource]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe
307-
308-
[computervision_docs]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/home
309-
310-
[ref_computervisionclient]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python
311-
312-
313-
[ref_computervisionclient_analyze_image]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#analyze-image-url--visual-features-none--details-none--language--en---custom-headers-none--raw-false----operation-config-
314-
[ref_computervisionclient_list_models]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#list-models-custom-headers-none--raw-false----operation-config-
315-
[ref_computervisionclient_analyze_image_by_domain]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#analyze-image-by-domain-model--url--language--en---custom-headers-none--raw-false----operation-config-
316-
[ref_computervisionclient_describe_image]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#describe-image-url--max-candidates--1---language--en---custom-headers-none--raw-false----operation-config-
317-
[ref_computervisionclient_recognize_text]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#recognize-text-url--mode--custom-headers-none--raw-false----operation-config-
318-
[ref_computervisionclient_get_text_operation_result]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#get-text-operation-result-operation-id--custom-headers-none--raw-false----operation-config-
319-
[ref_computervisionclient_generate_thumbnail]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#generate-thumbnail-width--height--url--smart-cropping-false--custom-headers-none--raw-false--callback-none----operation-config-
320-
321-
322-
[ref_computervision_model_visualfeatures]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?view=azure-python
323-
324-
[ref_computervision_model_textoperationstatuscodes]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.textoperationstatuscodes?view=azure-python
19+
For code examples, see [Batch
20+
Management](https://docs.microsoft.com/python/api/overview/azure/batch)
21+
on docs.microsoft.com.
32522

326-
[computervision_request_units]:https://azure.microsoft.com/pricing/details/cognitive-services/computer-vision/
23+
## Provide Feedback
32724

328-
[recognize-text]:https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/computer_vision_samples.py
25+
If you encounter any bugs or have suggestions, please file an issue in
26+
the [Issues](https://github.com/Azure/azure-sdk-for-python/issues)
27+
section of the project.
32928

29+
![image](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-mgmt-batch%2FREADME.png)

0 commit comments

Comments
 (0)