From 691464fb14c96b9293f6e4c20e3d46fee8f2176c Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Mon, 28 Jan 2019 15:54:20 -0800 Subject: [PATCH 01/24] computer vision quickstart --- .../README.md | 278 ++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 azure-cognitiveservices-vision-computervision/README.md diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md new file mode 100644 index 000000000000..70edfbd66d6a --- /dev/null +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -0,0 +1,278 @@ +# Azure Cognitive Services Computer Vision SDK for Python + +The cloud-based Computer Vision service provides developers with access to advanced algorithms for processing images and returning information. Computer Vision works with popular image formats, such as JPEG and PNG. To analyze an image, you can either upload an image or specify an image URL. Computer Vision algorithms can analyze the content of an image in different ways, depending on the visual features you're interested in. For example, Computer Vision can determine if an image contains adult or racy content, or find all the faces in an image. + +You can use Computer Vision in your application to: + +- Analyze images for insight +- Extract text from images +- Moderate content in images + +Looking for source code or API reference? + +* [SDK source code][source_code] +* [SDK reference documentation][ref_computervision_sdk] + +## Prerequisites + +* Azure subscription - [Create a free account][azure_sub] +* Azure [Computer Vision resource][computer_vision_resource] - SQL API +* [Python 3.6+][python] + +If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command: + +```Bash +az cognitiveservices account create -n myresource -g myResourceGroup --kind ComputerVision --sku S1 -l WestEurope --yes +``` + +## Installation + +Install the Azure Cognitive Services Computer Vision SDK with [pip][pip], optionally within a [virtual environment][venv]. + +### Configure a virtual environment (optional) + +Although not required, you can keep your your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv]: + +```Bash +python3 -m venv azure-cognitiveservices-vision-computervision-environment +source azure-cognitiveservices-vision-computervision-environment/bin/activate +``` + +### Install the SDK + +Install the Azure Cognitive Services Computer Vision SDK for Python with [pip][pip]: + +```Bash +pip install git+https://github.com/johanste/azure-computervision-python.git@ux git+https://github.com/binderjoe/computervision-python-prototype.git@master +``` + +## Authentication + +Interaction with Computer Vision starts with an instance of the [Computer Vision][ref_computervisionclient] class. You need an **account**, its **URI**, and one of its **account keys** to instantiate the client object. + +### Get credentials + +Use the Azure CLI snippet below to populate two environment variables with the Computer Vision account URI and its primary master key (you can also find these values in the Azure portal). The snippet is formatted for the Bash shell. + +```Bash +RES_GROUP= +ACCT_NAME= + +export ACCOUNT_URI=$(az computervision show --resource-group $RES_GROUP --name $ACCT_NAME --query documentEndpoint --output tsv) +export ACCOUNT_KEY=$(az computervision list-keys --resource-group $RES_GROUP --name $ACCT_NAME --query primaryMasterKey --output tsv) +``` + +### Create client + +Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionAPI][ref_computervisionclient] client. + +```Python +from azure.cognitiveservices.vision.computervision import ComputerVisionAPI +from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes +from msrest.authentication import CognitiveServicesCredentials + +import os +region = os.environ['ACCOUNT_REGION'] +key = os.environ['ACCOUNT_KEY'] + +credentials = CognitiveServicesCredentials(key) +client = ComputerVisionAPI(region, credentials) +``` + +## Usage + +Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client, you can: + +* [Analyze an image][ref_database]: You can analyze images using Computer Vision to detect and provide insight about the visual features and characteristics of your images. You can either upload the contents of an image to analyze local images, or you can specify the URL of an image to analyze remote images. + +* [Moderate images in content][ref_item]: Detect adult and racy content in an image, rating the likelihood that the image contains either adult or racy content and generating a confidence score for both. The filter for adult and racy content detection can be set on a sliding scale to accommodate your preferences. + +* [Extract text from an image][ref_item]: Extract text using OCR from an image into a machine-readable character stream. If needed, OCR corrects the rotation of the recognized text, in degrees, around the horizontal image axis, and provides the frame coordinates of each word. OCR supports 25 languages, and automatically detects the language of extracted text. + +For more information about these resources, see [Working with Azure computer vision][computervision_resources]. + +## Examples + +The following sections provide several code snippets covering some of the most common computervision tasks, including: + +* [Analyze an image](#) +* [Analyze an image by domain](#) +* [Describe image](#insert-data) +* [Generate thumbnail](#delete-data) +* [Get list of domains](#query-the-database) + +### Analyze an image + +After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image for certain features. + +```Python +try: + image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags]) + + for tag in image_analysis.tags: + print(tag) + +except HTTPFailure as e: + if e.status_code != 409: + raise +``` + + +### Analyze an image by domain + +After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image by domain. + +```Python +domain = "landmarks" +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" +language = "en" + +try: + analysis = client.analyze_image_by_domain(domain, url, language) + + print(analysis.result) + +except HTTPFailure as e: + if e.status_code != 409: + raise +``` + +### Describe image + +This example creates a container with default settings. If a container with the same name already exists in the database (generating a `409 Conflict` error), the existing container is obtained instead. + +```Python +domain = "landmarks" +url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" +language = "en" +max_descriptions=3 + +try: + analysis = client.describe_image(url, max_descriptions, language) + + for caption in analysis.captions: + print(caption.text) + print(caption.confidence) + +except HTTPFailure as e: + if e.status_code != 409: + raise +``` + +### Generate thumbnail + +Retrieve an existing container from the database: + +```Python +database = client.get_database(database_name) +container = database.get_container(container_name) +``` + +### Get subject domain list + +The supported subject domains list contains all domains an image can be analyzed for. + +```Python +try: + models = client.list_models() + + for x in models.models_property: + print(x) + +except HTTPFailure as e: + if e.status_code != 409: + raise +``` + + + +## Troubleshooting + +### General + +When you interact with computervision DB using the Python SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests: + +[HTTP Status Codes for Azure computervision DB][computervision_http_status_codes] + +For example, if you try to create a container using an ID (name) that's already in use in your computervision DB database, a `409` error is returned, indicating the conflict. In the following snippet, the error is handled gracefully by catching the exception and displaying additional information about the error. + +```Python +try: + database.create_container(id=container_name, partition_key=PartitionKey(path="/productName") +except HTTPFailure as e: + if e.status_code == 409: + print("""Error creating container. +HTTP status code 409: The ID (name) provided for the container is already in use. +The container name must be unique within the database.""") + else: + raise +``` + +### Handle transient errors with retries + +While working with computervision DB, 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]. + +## Next steps + +### More sample code + +Several computervision DB 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 computervision DB: + +* [`examples.py`][sample_examples_misc] - Contains the code snippets found in this article. +* [`databasemanagementsample.py`][sample_database_mgmt] - Python code for working with Azure computervision DB databases, including: + * Create database + * Get database by ID + * Get database by query + * List databases in account + * Delete database +* [`documentmanagementsample.py`][sample_document_mgmt] - Example code for working with computervision DB documents, including: + * Create container + * Create documents (including those with differing schemas) + * Get document by ID + * Get all documents in a container + +### Additional documentation + +For more extensive documentation on the computervision DB service, see the [Azure computervision DB documentation][computervision_docs] on docs.microsoft.com. + + +[azure_cli]: https://docs.microsoft.com/cli/azure +[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker +[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry +[azure_portal]: https://portal.azure.com +[azure_sub]: https://azure.microsoft.com/free/ +[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview +[computervision_account_create]: https://docs.microsoft.com/azure/computervision-db/how-to-manage-database-account +[computervision_account]: https://docs.microsoft.com/azure/computervision-db/account-overview +[computervision_container]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-containers +[computervision_database]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-databases +[computervision_docs]: https://docs.microsoft.com/azure/computervision-db/ +[computervision_http_status_codes]: https://docs.microsoft.com/rest/api/computervision-db/http-status-codes-for-computervision +[computervision_item]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-items +[computervision_request_units]: https://docs.microsoft.com/azure/computervision-db/request-units +[computervision_resources]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items +[computervision_sql_queries]: https://docs.microsoft.com/azure/computervision-db/how-to-sql-query +[computervision_ttl]: https://docs.microsoft.com/azure/computervision-db/time-to-live +[pip]: https://pypi.org/project/pip/ +[python]: https://www.python.org/downloads/ +[ref_container_delete_item]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container.delete_item +[ref_container_query_items]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container.query_items +[ref_container_upsert_item]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container.upsert_item +[ref_container]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container +[ref_computervision_sdk]: http://computervisionproto.westus.azurecontainer.io +[ref_computervisionclient_create_database]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.computervisionClient.create_database +[ref_computervisionclient]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.computervisionClient +[ref_database]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Database +[ref_httpfailure]: https://docs.microsoft.com/python/api/azure-computervision/azure.computervision.errors.httpfailure +[ref_item]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Item +[sample_database_mgmt]: https://github.com/binderjoe/computervision-python-prototype/blob/master/examples/databasemanagementsample.py +[sample_document_mgmt]: https://github.com/binderjoe/computervision-python-prototype/blob/master/examples/documentmanagementsample.py +[sample_examples_misc]: https://github.com/binderjoe/computervision-python-prototype/blob/master/examples/examples.py +[source_code]: https://github.com/binderjoe/computervision-python-prototype +[venv]: https://docs.python.org/3/library/venv.html +[virtualenv]: https://virtualenv.pypa.io \ No newline at end of file From 0dfafdb309bbe557d819ee6547dec91a5801c802 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Mon, 28 Jan 2019 20:14:12 -0800 Subject: [PATCH 02/24] save thumbnail to file --- .../README.md | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index 70edfbd66d6a..87e98a61f86a 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -164,8 +164,24 @@ except HTTPFailure as e: Retrieve an existing container from the database: ```Python -database = client.get_database(database_name) -container = database.get_container(container_name) +from PIL import Image +import io + +width=50 +height=50 +url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" + +try: + thumbnail = client.generate_thumbnail(width, height, url) + + for x in thumbnail: + image = Image.open(io.BytesIO(x)) + image.save('thumbnail.jpg') + + +except HTTPFailure as e: + if e.status_code != 409: + raise ``` ### Get subject domain list From 96646f491da02f054cec2bbbafbb1ab4771be536 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Tue, 29 Jan 2019 11:26:44 -0800 Subject: [PATCH 03/24] edits --- .../README.md | 171 ++++++++---------- 1 file changed, 79 insertions(+), 92 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index 87e98a61f86a..cb309c3efd23 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -1,12 +1,14 @@ # Azure Cognitive Services Computer Vision SDK for Python -The cloud-based Computer Vision service provides developers with access to advanced algorithms for processing images and returning information. Computer Vision works with popular image formats, such as JPEG and PNG. To analyze an image, you can either upload an image or specify an image URL. Computer Vision algorithms can analyze the content of an image in different ways, depending on the visual features you're interested in. For example, Computer Vision can determine if an image contains adult or racy content, or find all the faces in an image. +The cloud-based Computer Vision service provides developers with access to advanced algorithms for processing images and returning information. This service works with popular image formats, such as JPEG and PNG. + +To analyze an image, you can either upload an image or specify an image URL. Computer Vision algorithms analyze the content of an image in different ways, depending on the visual features you're interested in. For example, Computer Vision can determine if an image contains adult or racy content, or find all the faces in an image. You can use Computer Vision in your application to: - Analyze images for insight - Extract text from images -- Moderate content in images +- Generate thumbnails Looking for source code or API reference? @@ -22,7 +24,17 @@ Looking for source code or API reference? If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command: ```Bash -az cognitiveservices account create -n myresource -g myResourceGroup --kind ComputerVision --sku S1 -l WestEurope --yes +RES_REGION=westeurope +RES_GROUP= +ACCT_NAME= + +az cognitiveservices account create \ +-n $ACCT_NAME \ +-g $RES_GROUP \ +-l $RES_REGION \ +--kind ComputerVision \ +--sku S1 \ + --yes ``` ## Installation @@ -31,7 +43,7 @@ Install the Azure Cognitive Services Computer Vision SDK with [pip][pip], option ### Configure a virtual environment (optional) -Although not required, you can keep your your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv]: +Although not required, you can keep your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv]: ```Bash python3 -m venv azure-cognitiveservices-vision-computervision-environment @@ -48,18 +60,28 @@ pip install git+https://github.com/johanste/azure-computervision-python.git@ux g ## Authentication -Interaction with Computer Vision starts with an instance of the [Computer Vision][ref_computervisionclient] class. You need an **account**, its **URI**, and one of its **account keys** to instantiate the client object. +To use the Computer Vision SDK, create an instance of the [Computer Vision][ref_computervisionclient]. Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. ### Get credentials Use the Azure CLI snippet below to populate two environment variables with the Computer Vision account URI and its primary master key (you can also find these values in the Azure portal). The snippet is formatted for the Bash shell. ```Bash -RES_GROUP= +RES_GROUP= ACCT_NAME= -export ACCOUNT_URI=$(az computervision show --resource-group $RES_GROUP --name $ACCT_NAME --query documentEndpoint --output tsv) -export ACCOUNT_KEY=$(az computervision list-keys --resource-group $RES_GROUP --name $ACCT_NAME --query primaryMasterKey --output tsv) +export ACCOUNT_REGION=$(az cognitiveservices account show \ +--resource-group $RES_GROUP \ +--name $ACCT_NAME \ +--query location \ +--output tsv) + +export ACCOUNT_KEY=$(az cognitiveservices account keys list \ +--name $ACCT_NAME \ +--resource-group $RES_GROUP \ +--name $ACCT_NAME \ +--query key1 \ +--output tsv) ``` ### Create client @@ -83,63 +105,51 @@ client = ComputerVisionAPI(region, credentials) Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client, you can: -* [Analyze an image][ref_database]: You can analyze images using Computer Vision to detect and provide insight about the visual features and characteristics of your images. You can either upload the contents of an image to analyze local images, or you can specify the URL of an image to analyze remote images. +* [Analyze an image][ref_analyzeimage]: You can analyze an internet image for certain features such as faces, colors, tags. The image can be local to the computer, on the internet. -* [Moderate images in content][ref_item]: Detect adult and racy content in an image, rating the likelihood that the image contains either adult or racy content and generating a confidence score for both. The filter for adult and racy content detection can be set on a sliding scale to accommodate your preferences. +* [Moderate images in content][ref_moderateimage]: An image can be analyzed for adult content. -* [Extract text from an image][ref_item]: Extract text using OCR from an image into a machine-readable character stream. If needed, OCR corrects the rotation of the recognized text, in degrees, around the horizontal image axis, and provides the frame coordinates of each word. OCR supports 25 languages, and automatically detects the language of extracted text. +* [Extract text from an image][ref_extracttext]: An image can be scanned for text. In order to complete the analysis, Computer Vision may correct rotation before analysis. Computer Vision supports 25 languages, and automatically detects the language of extracted text. For more information about these resources, see [Working with Azure computer vision][computervision_resources]. ## Examples -The following sections provide several code snippets covering some of the most common computervision tasks, including: +The following sections provide several code snippets covering some of the most common Computer Vision tasks, including: -* [Analyze an image](#) -* [Analyze an image by domain](#) -* [Describe image](#insert-data) -* [Generate thumbnail](#delete-data) -* [Get list of domains](#query-the-database) +* [Analyze an image](#analyze-an-image) +* [Analyze an image by domain](#analyze-an-image-by-domain) +* [Get text description of an image](#get-text-description-of-an-image) +* [Generate thumbnail](#generate-thumbnail) +* [Get subject domain list](#get-subject-domain-list) ### Analyze an image After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image for certain features. ```Python -try: - image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags]) - - for tag in image_analysis.tags: - print(tag) +image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags]) -except HTTPFailure as e: - if e.status_code != 409: - raise +for tag in image_analysis.tags: + print(tag) ``` ### Analyze an image by domain -After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image by domain. +After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image by subject domain. ```Python domain = "landmarks" 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" language = "en" -try: - analysis = client.analyze_image_by_domain(domain, url, language) - - print(analysis.result) - -except HTTPFailure as e: - if e.status_code != 409: - raise +analysis = client.analyze_image_by_domain(domain, url, language) ``` -### Describe image +### Get text description of an image -This example creates a container with default settings. If a container with the same name already exists in the database (generating a `409 Conflict` error), the existing container is obtained instead. +After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can get a language-based text description of an image. ```Python domain = "landmarks" @@ -147,21 +157,16 @@ url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-franci language = "en" max_descriptions=3 -try: - analysis = client.describe_image(url, max_descriptions, language) +analysis = client.describe_image(url, max_descriptions, language) - for caption in analysis.captions: - print(caption.text) - print(caption.confidence) - -except HTTPFailure as e: - if e.status_code != 409: - raise +for caption in analysis.captions: + print(caption.text) + print(caption.confidence) ``` ### Generate thumbnail -Retrieve an existing container from the database: +After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can generate a thumbnail (JPG) of an image. ```Python from PIL import Image @@ -171,86 +176,68 @@ width=50 height=50 url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" -try: - thumbnail = client.generate_thumbnail(width, height, url) - - for x in thumbnail: - image = Image.open(io.BytesIO(x)) - image.save('thumbnail.jpg') +thumbnail = client.generate_thumbnail(width, height, url) - -except HTTPFailure as e: - if e.status_code != 409: - raise +for x in thumbnail: + image = Image.open(io.BytesIO(x)) +image.save('thumbnail.jpg') ``` ### Get subject domain list -The supported subject domains list contains all domains an image can be analyzed for. +After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, review the subject domains used to analyze your image. ```Python -try: - models = client.list_models() - - for x in models.models_property: - print(x) +models = client.list_models() -except HTTPFailure as e: - if e.status_code != 409: - raise +for x in models.models_property: + print(x) ``` - ## Troubleshooting ### General -When you interact with computervision DB using the Python SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests: +When you interact with the [ComputerVisionAPI][ref_computervisionclient] client using the Python SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests: -[HTTP Status Codes for Azure computervision DB][computervision_http_status_codes] +[HTTP Status Codes for Azure ComputerVisionAPI][computervision_http_status_codes] -For example, if you try to create a container using an ID (name) that's already in use in your computervision DB database, a `409` error is returned, indicating the conflict. In the following snippet, the error is handled gracefully by catching the exception and displaying additional information about the error. +For example, if you try to analyze an image with an invalid key, a `401` error is returned. In the following snippet, the error is handled gracefully by catching the exception and displaying additional information about the error. ```Python + +domain = "landmarks" +url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" +language = "en" +max_descriptions=3 + try: - database.create_container(id=container_name, partition_key=PartitionKey(path="/productName") + analysis = client.describe_image(url, max_descriptions, language) + + for caption in analysis.captions: + print(caption.text) + print(caption.confidence) except HTTPFailure as e: - if e.status_code == 409: - print("""Error creating container. -HTTP status code 409: The ID (name) provided for the container is already in use. -The container name must be unique within the database.""") + if e.status_code == 401: + print("""Error unauthorized. +HTTP status code 401: your Computer Vision account is not authorized. Make sure your key and region are correct.""") else: raise ``` ### Handle transient errors with retries -While working with computervision DB, 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]. +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]. ## Next steps ### More sample code -Several computervision DB 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 computervision DB: +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: * [`examples.py`][sample_examples_misc] - Contains the code snippets found in this article. -* [`databasemanagementsample.py`][sample_database_mgmt] - Python code for working with Azure computervision DB databases, including: - * Create database - * Get database by ID - * Get database by query - * List databases in account - * Delete database -* [`documentmanagementsample.py`][sample_document_mgmt] - Example code for working with computervision DB documents, including: - * Create container - * Create documents (including those with differing schemas) - * Get document by ID - * Get all documents in a container + ### Additional documentation From b67018cf4693a9d582ab348c718a2c2c431b6a2d Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 30 Jan 2019 07:26:50 -0800 Subject: [PATCH 04/24] edits based on Marsh's feedback --- .../README.md | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index cb309c3efd23..bc85dcd93c37 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -29,12 +29,12 @@ RES_GROUP= ACCT_NAME= az cognitiveservices account create \ --n $ACCT_NAME \ --g $RES_GROUP \ --l $RES_REGION \ ---kind ComputerVision \ ---sku S1 \ - --yes + --resource-group $RES_GROUP \ + --name $ACCT_NAME \ + --location $RES_REGION \ + --kind ComputerVision \ + --sku S1 \ + --yes ``` ## Installation @@ -43,11 +43,11 @@ Install the Azure Cognitive Services Computer Vision SDK with [pip][pip], option ### Configure a virtual environment (optional) -Although not required, you can keep your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv]: +Although not required, you can keep your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv], such as `cogsrv-vision-env`: ```Bash -python3 -m venv azure-cognitiveservices-vision-computervision-environment -source azure-cognitiveservices-vision-computervision-environment/bin/activate +python3 -m venv cogsrv-vision-env +source cogsrv-vision-env/bin/activate ``` ### Install the SDK @@ -55,33 +55,35 @@ source azure-cognitiveservices-vision-computervision-environment/bin/activate Install the Azure Cognitive Services Computer Vision SDK for Python with [pip][pip]: ```Bash -pip install git+https://github.com/johanste/azure-computervision-python.git@ux git+https://github.com/binderjoe/computervision-python-prototype.git@master +pip install azure-cognitiveservices-vision-computervision ``` ## Authentication -To use the Computer Vision SDK, create an instance of the [Computer Vision][ref_computervisionclient]. Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. +Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. + +Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient]. ### Get credentials -Use the Azure CLI snippet below to populate two environment variables with the Computer Vision account URI and its primary master key (you can also find these values in the Azure portal). The snippet is formatted for the Bash shell. +Use the Azure CLI snippet below to populate two environment variables with the Computer Vision account URI and one of its key (you can also find these values in the Azure portal). The snippet is formatted for the Bash shell. ```Bash RES_GROUP= ACCT_NAME= export ACCOUNT_REGION=$(az cognitiveservices account show \ ---resource-group $RES_GROUP \ ---name $ACCT_NAME \ ---query location \ ---output tsv) + --resource-group $RES_GROUP \ + --name $ACCT_NAME \ + --query location \ + --output tsv) export ACCOUNT_KEY=$(az cognitiveservices account keys list \ ---name $ACCT_NAME \ ---resource-group $RES_GROUP \ ---name $ACCT_NAME \ ---query key1 \ ---output tsv) + --name $ACCT_NAME \ + --resource-group $RES_GROUP \ + --name $ACCT_NAME \ + --query key1 \ + --output tsv) ``` ### Create client @@ -105,7 +107,7 @@ client = ComputerVisionAPI(region, credentials) Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client, you can: -* [Analyze an image][ref_analyzeimage]: You can analyze an internet image for certain features such as faces, colors, tags. The image can be local to the computer, on the internet. +* [Analyze an image][ref_analyzeimage]: You can analyze an iimage for certain features such as faces, colors, tags. * [Moderate images in content][ref_moderateimage]: An image can be analyzed for adult content. @@ -125,9 +127,14 @@ The following sections provide several code snippets covering some of the most c ### Analyze an image -After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image for certain features. +You can analyze an image for certain features. Use the `visual_features` property to set the types of analysis to perform on the image. Common values are: + + * `VisualFeatureTypes.tags` + * `VisualFeatureTypes.description` ```Python +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" + image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags]) for tag in image_analysis.tags: @@ -137,7 +144,7 @@ for tag in image_analysis.tags: ### Analyze an image by domain -After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can analyze an image by subject domain. +You can analyze an image by subject domain. Get the [list of support subject domains](#get-subject-domain-list) in order to use the correct domain name. ```Python domain = "landmarks" @@ -145,11 +152,19 @@ url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Broadway_and_Ti language = "en" analysis = client.analyze_image_by_domain(domain, url, language) + +for landmark in analysis.result["landmarks"]: + print(landmark["name"]) + print(landmark["confidence"]) ``` ### Get text description of an image -After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can get a language-based text description of an image. +You can get a language-based text description of an 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 + * a train crossing a bridge over a large body of water ```Python domain = "landmarks" @@ -166,7 +181,7 @@ for caption in analysis.captions: ### Generate thumbnail -After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, you can generate a thumbnail (JPG) of an image. +You can generate a thumbnail (JPG) of an image. The thumbnail does not need to be in the same proportions as the original image. ```Python from PIL import Image @@ -185,7 +200,7 @@ image.save('thumbnail.jpg') ### Get subject domain list -After authenticating your [ComputerVisionAPI][ref_computervisionclient] client, review the subject domains used to analyze your image. +Review the subject domains used to analyze your image. These domain names are used when [analyzing an image by domain](#analyze-an-image-by-domain). An example of a domain is `landmarks`. ```Python models = client.list_models() From 0acdadd4166b31a6a72b2f019df79317b82562cd Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 30 Jan 2019 07:44:07 -0800 Subject: [PATCH 05/24] edits --- .../README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index bc85dcd93c37..f39c1697f172 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -107,11 +107,9 @@ client = ComputerVisionAPI(region, credentials) Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client, you can: -* [Analyze an image][ref_analyzeimage]: You can analyze an iimage for certain features such as faces, colors, tags. - -* [Moderate images in content][ref_moderateimage]: An image can be analyzed for adult content. - -* [Extract text from an image][ref_extracttext]: An image can be scanned for text. In order to complete the analysis, Computer Vision may correct rotation before analysis. Computer Vision supports 25 languages, and automatically detects the language of extracted text. +* Analyze an image: You can analyze an iimage for certain features such as faces, colors, tags. +* Moderate images in content: An image can be analyzed for adult content. +* Extract text from an image: An image can be scanned for text. In order to complete the analysis, Computer Vision may correct rotation before analysis. Computer Vision supports 25 languages, and automatically detects the language of extracted text. For more information about these resources, see [Working with Azure computer vision][computervision_resources]. @@ -129,8 +127,8 @@ The following sections provide several code snippets covering some of the most c You can analyze an image for certain features. Use the `visual_features` property to set the types of analysis to perform on the image. Common values are: - * `VisualFeatureTypes.tags` - * `VisualFeatureTypes.description` + * VisualFeatureTypes.tags + * VisualFeatureTypes.description ```Python 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" From bfaa0ded0bc945519b47228eae8808fb20603df7 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 30 Jan 2019 07:49:46 -0800 Subject: [PATCH 06/24] edits --- .../README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index f39c1697f172..05393246ef96 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -18,7 +18,7 @@ Looking for source code or API reference? ## Prerequisites * Azure subscription - [Create a free account][azure_sub] -* Azure [Computer Vision resource][computer_vision_resource] - SQL API +* Azure [Computer Vision resource][computer_vision_resource] * [Python 3.6+][python] If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command: @@ -125,10 +125,7 @@ The following sections provide several code snippets covering some of the most c ### Analyze an image -You can analyze an image for certain features. Use the `visual_features` property to set the types of analysis to perform on the image. Common values are: - - * VisualFeatureTypes.tags - * VisualFeatureTypes.description +You can analyze an image for certain features. Use the `visual_features` property to set the types of analysis to perform on the image. Common values are `VisualFeatureTypes.tags` and `VisualFeatureTypes.description`. ```Python 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" @@ -158,11 +155,7 @@ for landmark in analysis.result["landmarks"]: ### Get text description of an image -You can get a language-based text description of an 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 - * a train crossing a bridge over a large body of water +You can get a language-based text description of an 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`. ```Python domain = "landmarks" @@ -263,6 +256,7 @@ For more extensive documentation on the computervision DB service, see the [Azur [azure_portal]: https://portal.azure.com [azure_sub]: https://azure.microsoft.com/free/ [cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview +[computer_vision_resource]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe [computervision_account_create]: https://docs.microsoft.com/azure/computervision-db/how-to-manage-database-account [computervision_account]: https://docs.microsoft.com/azure/computervision-db/account-overview [computervision_container]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-containers From e98d3cf2fb81328a39d7ea0fd5e4f3b40f378adc Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 30 Jan 2019 11:22:04 -0800 Subject: [PATCH 07/24] edits based on Anna's feedback --- azure-cognitiveservices-vision-computervision/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index 05393246ef96..f29d1bfb8a10 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -226,8 +226,7 @@ try: print(caption.confidence) except HTTPFailure as e: if e.status_code == 401: - print("""Error unauthorized. -HTTP status code 401: your Computer Vision account is not authorized. Make sure your key and region are correct.""") + print("Error unauthorized. Make sure your key and region are correct.") else: raise ``` From e1817c5bd4ffe10f2f03134caaeebb265e6177be Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Fri, 1 Feb 2019 09:44:18 -0800 Subject: [PATCH 08/24] edits based on feedback - some links fixed - tbd - read of links --- .../README.md | 139 ++++++++++++------ 1 file changed, 92 insertions(+), 47 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index f29d1bfb8a10..c4bd1c85b8f5 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -62,11 +62,11 @@ pip install azure-cognitiveservices-vision-computervision Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. -Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient]. +Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient] client object. ### Get credentials -Use the Azure CLI snippet below to populate two environment variables with the Computer Vision account URI and one of its key (you can also find these values in the Azure portal). The snippet is formatted for the Bash shell. +Use the Azure CLI 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). The snippet is formatted for the Bash shell. ```Bash RES_GROUP= @@ -88,7 +88,7 @@ export ACCOUNT_KEY=$(az cognitiveservices account keys list \ ### Create client -Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionAPI][ref_computervisionclient] client. +Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionAPI][ref_computervisionclient] client object. ```Python from azure.cognitiveservices.vision.computervision import ComputerVisionAPI @@ -105,11 +105,11 @@ client = ComputerVisionAPI(region, credentials) ## Usage -Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client, you can: +Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client object, you can: * Analyze an image: You can analyze an iimage for certain features such as faces, colors, tags. -* Moderate images in content: An image can be analyzed for adult content. -* Extract text from an image: An image can be scanned for text. In order to complete the analysis, Computer Vision may correct rotation before analysis. Computer Vision supports 25 languages, and automatically detects the language of extracted text. +* Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image. +* Get description of an image: Get a description of the image based on its subject domain. For more information about these resources, see [Working with Azure computer vision][computervision_resources]. @@ -120,12 +120,13 @@ The following sections provide several code snippets covering some of the most c * [Analyze an image](#analyze-an-image) * [Analyze an image by domain](#analyze-an-image-by-domain) * [Get text description of an image](#get-text-description-of-an-image) +* [Get text from image](#get-text-from-image) * [Generate thumbnail](#generate-thumbnail) * [Get subject domain list](#get-subject-domain-list) ### Analyze an image -You can analyze an image for certain features. Use the `visual_features` property to set the types of analysis to perform on the image. Common values are `VisualFeatureTypes.tags` and `VisualFeatureTypes.description`. +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`. ```Python 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" @@ -136,10 +137,20 @@ for tag in image_analysis.tags: print(tag) ``` +### Get subject domain list + +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`. + +```Python +models = client.list_models() + +for x in models.models_property: + print(x) +``` ### Analyze an image by domain -You can analyze an image by subject domain. Get the [list of support subject domains](#get-subject-domain-list) in order to use the correct domain name. +You can analyze an image by subject domain with [`analyze_image_by_domain`][ref_computervisionclient_analyze_image_by_domain]. Get the [list of support subject domains](#get-subject-domain-list) in order to use the correct domain name. ```Python domain = "landmarks" @@ -155,7 +166,7 @@ for landmark in analysis.result["landmarks"]: ### Get text description of an image -You can get a language-based text description of an 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`. +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`. ```Python domain = "landmarks" @@ -170,9 +181,41 @@ for caption in analysis.captions: print(caption.confidence) ``` +### Get text from image + +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. + +```Python +url = "https://azurecomcdn.azureedge.net/cvt-1979217d3d0d31c5c87cbd991bccfee2d184b55eeb4081200012bdaf6a65601a/images/shared/cognitive-services-demos/read-text/read-1-thumbnail.png" +mode = TextRecognitionMode.handwritten +raw = True +custom_headers = None +numberOfCharsInOperationId = 36 + +# SDK call +rawHttpResponse = client.recognize_text(url, mode, custom_headers, raw) + +# Get ID from returned headers +operationLocation = rawHttpResponse.headers["Operation-Location"] +idLocation = len(operationLocation) - numberOfCharsInOperationId +operationId = operationLocation[idLocation:] + +# SDK call +result = client.get_text_operation_result(operationId) + +# Get data +if result.status == TextOperationStatusCodes.succeeded: + + for line in result.recognition_result.lines: + print(line.text) + print(line.bounding_box) +``` + ### Generate thumbnail -You can generate a thumbnail (JPG) of an image. The thumbnail does not need to be in the same proportions as the original image. +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. + +This example uses the [Pillow][pypi_pillow] package to save the new thumbnail image locally. ```Python from PIL import Image @@ -189,23 +232,11 @@ for x in thumbnail: image.save('thumbnail.jpg') ``` -### Get subject domain list - -Review the subject domains used to analyze your image. These domain names are used when [analyzing an image by domain](#analyze-an-image-by-domain). An example of a domain is `landmarks`. - -```Python -models = client.list_models() - -for x in models.models_property: - print(x) -``` - - ## Troubleshooting ### General -When you interact with the [ComputerVisionAPI][ref_computervisionclient] client using the Python SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests: +When you interact with the [ComputerVisionAPI][ref_computervisionclient] client object using the Python SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests: [HTTP Status Codes for Azure ComputerVisionAPI][computervision_http_status_codes] @@ -249,39 +280,53 @@ Several Computer Vision Python SDK samples are available to you in the SDK's Git For more extensive documentation on the computervision DB service, see the [Azure computervision DB documentation][computervision_docs] on docs.microsoft.com. +[pip]: https://pypi.org/project/pip/ +[python]: https://www.python.org/downloads/ + [azure_cli]: https://docs.microsoft.com/cli/azure [azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker [azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry [azure_portal]: https://portal.azure.com [azure_sub]: https://azure.microsoft.com/free/ + [cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview + +[venv]: https://docs.python.org/3/library/venv.html +[virtualenv]: https://virtualenv.pypa.io + +[source_code]: https://github.com/binderjoe/computervision-python-prototype + + +[pypi_pillow]:https://pypi.org/project/Pillow/ + +[ref_computervision_sdk]: http://computervisionproto.westus.azurecontainer.io +[ref_httpfailure]: https://docs.microsoft.com/python/api/azure-computervision/azure.computervision.errors.httpfailure + + [computer_vision_resource]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe -[computervision_account_create]: https://docs.microsoft.com/azure/computervision-db/how-to-manage-database-account -[computervision_account]: https://docs.microsoft.com/azure/computervision-db/account-overview -[computervision_container]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-containers -[computervision_database]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-databases + [computervision_docs]: https://docs.microsoft.com/azure/computervision-db/ [computervision_http_status_codes]: https://docs.microsoft.com/rest/api/computervision-db/http-status-codes-for-computervision -[computervision_item]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items#azure-computervision-items -[computervision_request_units]: https://docs.microsoft.com/azure/computervision-db/request-units [computervision_resources]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items -[computervision_sql_queries]: https://docs.microsoft.com/azure/computervision-db/how-to-sql-query + [computervision_ttl]: https://docs.microsoft.com/azure/computervision-db/time-to-live -[pip]: https://pypi.org/project/pip/ -[python]: https://www.python.org/downloads/ -[ref_container_delete_item]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container.delete_item -[ref_container_query_items]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container.query_items -[ref_container_upsert_item]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container.upsert_item -[ref_container]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Container -[ref_computervision_sdk]: http://computervisionproto.westus.azurecontainer.io -[ref_computervisionclient_create_database]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.computervisionClient.create_database + [ref_computervisionclient]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.computervisionClient -[ref_database]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Database -[ref_httpfailure]: https://docs.microsoft.com/python/api/azure-computervision/azure.computervision.errors.httpfailure -[ref_item]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.Item -[sample_database_mgmt]: https://github.com/binderjoe/computervision-python-prototype/blob/master/examples/databasemanagementsample.py -[sample_document_mgmt]: https://github.com/binderjoe/computervision-python-prototype/blob/master/examples/documentmanagementsample.py -[sample_examples_misc]: https://github.com/binderjoe/computervision-python-prototype/blob/master/examples/examples.py -[source_code]: https://github.com/binderjoe/computervision-python-prototype -[venv]: https://docs.python.org/3/library/venv.html -[virtualenv]: https://virtualenv.pypa.io \ No newline at end of file + + +[ref_computervisionclient_analyze_image]: https://docs.microsoft.com/en-us/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- +[ref_computervisionclient_list_models]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#list-models-custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_analyze_image_by_domain]:https://docs.microsoft.com/en-us/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- +[ref_computervisionclient_describe_image]:https://docs.microsoft.com/en-us/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- +[ref_computervisionclient_recognize_text]:https://docs.microsoft.com/en-us/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- +[ref_computervisionclient_get_text_operation_result]:https://docs.microsoft.com/en-us/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- +[ref_computervisionclient_generate_thumbnail]:https://docs.microsoft.com/en-us/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- + + +[ref_computervision_model_visualfeatures]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?view=azure-python + +[ref_computervision_model_textoperationstatuscodes]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.textoperationstatuscodes?view=azure-python + + + + From 551da345101e21b31fac0710fae74fcd0cd8eead Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Fri, 1 Feb 2019 12:47:41 -0800 Subject: [PATCH 09/24] links should be fixed --- .../README.md | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index c4bd1c85b8f5..2cb17d21a421 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -1,8 +1,6 @@ # Azure Cognitive Services Computer Vision SDK for Python -The cloud-based Computer Vision service provides developers with access to advanced algorithms for processing images and returning information. This service works with popular image formats, such as JPEG and PNG. - -To analyze an image, you can either upload an image or specify an image URL. Computer Vision algorithms analyze the content of an image in different ways, depending on the visual features you're interested in. For example, Computer Vision can determine if an image contains adult or racy content, or find all the faces in an image. +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. For example, Computer Vision can determine if an image contains adult or racy content, find all the faces in an image, get handwritten or printed text. This service works with popular image formats, such as JPEG and PNG. You can use Computer Vision in your application to: @@ -12,13 +10,14 @@ You can use Computer Vision in your application to: Looking for source code or API reference? -* [SDK source code][source_code] +* [Pip package][pypi_computervision] * [SDK reference documentation][ref_computervision_sdk] +* [SDK source code][source_code] ## Prerequisites * Azure subscription - [Create a free account][azure_sub] -* Azure [Computer Vision resource][computer_vision_resource] +* Azure [Computer Vision resource][computervision_resource] * [Python 3.6+][python] If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command: @@ -111,7 +110,7 @@ Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client o * Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image. * Get description of an image: Get a description of the image based on its subject domain. -For more information about these resources, see [Working with Azure computer vision][computervision_resources]. +For more information about this service, see [What is Computer Vision?][computervision_docs]. ## Examples @@ -120,7 +119,7 @@ The following sections provide several code snippets covering some of the most c * [Analyze an image](#analyze-an-image) * [Analyze an image by domain](#analyze-an-image-by-domain) * [Get text description of an image](#get-text-description-of-an-image) -* [Get text from image](#get-text-from-image) +* [Get handwritten text from image](#get-text-from-image) * [Generate thumbnail](#generate-thumbnail) * [Get subject domain list](#get-subject-domain-list) @@ -150,7 +149,7 @@ for x in models.models_property: ### Analyze an image by domain -You can analyze an image by subject domain with [`analyze_image_by_domain`][ref_computervisionclient_analyze_image_by_domain]. Get the [list of support subject domains](#get-subject-domain-list) in order to use the correct domain name. +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. ```Python domain = "landmarks" @@ -172,7 +171,7 @@ You can get a language-based text description of an image with [`describe_image` domain = "landmarks" url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" language = "en" -max_descriptions=3 +max_descriptions = 3 analysis = client.describe_image(url, max_descriptions, language) @@ -221,14 +220,15 @@ This example uses the [Pillow][pypi_pillow] package to save the new thumbnail im from PIL import Image import io -width=50 -height=50 +width = 50 +height = 50 url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" thumbnail = client.generate_thumbnail(width, height, url) for x in thumbnail: image = Image.open(io.BytesIO(x)) + image.save('thumbnail.jpg') ``` @@ -236,18 +236,16 @@ image.save('thumbnail.jpg') ### General -When you interact with the [ComputerVisionAPI][ref_computervisionclient] client object using the Python SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests: +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. -[HTTP Status Codes for Azure ComputerVisionAPI][computervision_http_status_codes] - -For example, if you try to analyze an image with an invalid key, a `401` error is returned. In the following snippet, the error is handled gracefully by catching the exception and displaying additional information about the error. +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. ```Python domain = "landmarks" url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" language = "en" -max_descriptions=3 +max_descriptions = 3 try: analysis = client.describe_image(url, max_descriptions, language) @@ -264,7 +262,7 @@ except HTTPFailure as e: ### Handle transient errors with retries -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]. +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]. ## Next steps @@ -272,12 +270,11 @@ While working with the [ComputerVisionAPI][ref_computervisionclient] client , yo 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: -* [`examples.py`][sample_examples_misc] - Contains the code snippets found in this article. - +* [recognize_text][recognize-text] ### Additional documentation -For more extensive documentation on the computervision DB service, see the [Azure computervision DB documentation][computervision_docs] on docs.microsoft.com. +For more extensive documentation on the Computer Vision service, see the [Azure Computer Vision documentation][computervision_docs] on docs.microsoft.com. [pip]: https://pypi.org/project/pip/ @@ -294,20 +291,19 @@ For more extensive documentation on the computervision DB service, see the [Azur [venv]: https://docs.python.org/3/library/venv.html [virtualenv]: https://virtualenv.pypa.io -[source_code]: https://github.com/binderjoe/computervision-python-prototype - +[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-cognitiveservices-vision-computervision +[pypi_computervision]:https://pypi.org/project/azure-cognitiveservices-vision-computervision/ [pypi_pillow]:https://pypi.org/project/Pillow/ -[ref_computervision_sdk]: http://computervisionproto.westus.azurecontainer.io -[ref_httpfailure]: https://docs.microsoft.com/python/api/azure-computervision/azure.computervision.errors.httpfailure +[ref_computervision_sdk]: https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision?view=azure-python +[ref_computervision_computervisionerrorexception]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.computervisionerrorexception?view=azure-python +[ref_httpfailure]: https://docs.microsoft.com/en-us/python/api/msrest/msrest.exceptions.httpoperationerror?view=azure-python -[computer_vision_resource]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe +[computervision_resource]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe -[computervision_docs]: https://docs.microsoft.com/azure/computervision-db/ -[computervision_http_status_codes]: https://docs.microsoft.com/rest/api/computervision-db/http-status-codes-for-computervision -[computervision_resources]: https://docs.microsoft.com/azure/computervision-db/databases-containers-items +[computervision_docs]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/home [computervision_ttl]: https://docs.microsoft.com/azure/computervision-db/time-to-live @@ -327,6 +323,7 @@ For more extensive documentation on the computervision DB service, see the [Azur [ref_computervision_model_textoperationstatuscodes]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.textoperationstatuscodes?view=azure-python +[computervision_request_units]:https://azure.microsoft.com/en-us/pricing/details/cognitive-services/computer-vision/ - +[recognize-text]:https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/computer_vision_samples.py From b8d56a3232e49bfa04084addf4b73028df77a847 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Fri, 1 Feb 2019 13:10:59 -0800 Subject: [PATCH 10/24] remove unused links --- azure-cognitiveservices-vision-computervision/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index 2cb17d21a421..e6dc3645e4fa 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -42,7 +42,7 @@ Install the Azure Cognitive Services Computer Vision SDK with [pip][pip], option ### Configure a virtual environment (optional) -Although not required, you can keep your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv], such as `cogsrv-vision-env`: +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`: ```Bash python3 -m venv cogsrv-vision-env @@ -65,7 +65,7 @@ Use these values when you create the instance of the [ComputerVisionAPI][ref_com ### Get credentials -Use the Azure CLI 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). The snippet is formatted for the Bash shell. +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. ```Bash RES_GROUP= @@ -305,8 +305,6 @@ For more extensive documentation on the Computer Vision service, see the [Azure [computervision_docs]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/home -[computervision_ttl]: https://docs.microsoft.com/azure/computervision-db/time-to-live - [ref_computervisionclient]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.computervisionClient From 7d75a0d10ad863832cf7103a8ffe78655d1f6291 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Fri, 1 Feb 2019 15:17:48 -0800 Subject: [PATCH 11/24] fix spelling --- azure-cognitiveservices-vision-computervision/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index e6dc3645e4fa..08a4285f7d13 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -106,7 +106,7 @@ client = ComputerVisionAPI(region, credentials) Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client object, you can: -* Analyze an image: You can analyze an iimage for certain features such as faces, colors, tags. +* Analyze an image: You can analyze an image for certain features such as faces, colors, tags. * Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image. * Get description of an image: Get a description of the image based on its subject domain. From 5396c0ddcef821a6897ea2a4bec9cd9c3bf28a88 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Tue, 5 Feb 2019 12:38:11 -0800 Subject: [PATCH 12/24] edits based on Marsh's feedback --- .../README.md | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index 08a4285f7d13..a13a62617250 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -8,11 +8,10 @@ You can use Computer Vision in your application to: - Extract text from images - Generate thumbnails -Looking for source code or API reference? +Looking for more documentation? -* [Pip package][pypi_computervision] -* [SDK reference documentation][ref_computervision_sdk] -* [SDK source code][source_code] +* [SDK reference documentation](https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision) +* [Cognitive Services Computer Vision documentation](https://docs.microsoft.com/azure/cognitive-services/computer-vision/) ## Prerequisites @@ -78,7 +77,6 @@ export ACCOUNT_REGION=$(az cognitiveservices account show \ --output tsv) export ACCOUNT_KEY=$(az cognitiveservices account keys list \ - --name $ACCT_NAME \ --resource-group $RES_GROUP \ --name $ACCT_NAME \ --query key1 \ @@ -117,11 +115,11 @@ For more information about this service, see [What is Computer Vision?][computer The following sections provide several code snippets covering some of the most common Computer Vision tasks, including: * [Analyze an image](#analyze-an-image) +* [Get subject domain list](#get-subject-domain-list) * [Analyze an image by domain](#analyze-an-image-by-domain) * [Get text description of an image](#get-text-description-of-an-image) * [Get handwritten text from image](#get-text-from-image) * [Generate thumbnail](#generate-thumbnail) -* [Get subject domain list](#get-subject-domain-list) ### Analyze an image @@ -182,7 +180,7 @@ for caption in analysis.captions: ### Get text from image -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. +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. ```Python url = "https://azurecomcdn.azureedge.net/cvt-1979217d3d0d31c5c87cbd991bccfee2d184b55eeb4081200012bdaf6a65601a/images/shared/cognitive-services-demos/read-text/read-1-thumbnail.png" @@ -296,32 +294,32 @@ For more extensive documentation on the Computer Vision service, see the [Azure [pypi_computervision]:https://pypi.org/project/azure-cognitiveservices-vision-computervision/ [pypi_pillow]:https://pypi.org/project/Pillow/ -[ref_computervision_sdk]: https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision?view=azure-python -[ref_computervision_computervisionerrorexception]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.computervisionerrorexception?view=azure-python -[ref_httpfailure]: https://docs.microsoft.com/en-us/python/api/msrest/msrest.exceptions.httpoperationerror?view=azure-python +[ref_computervision_sdk]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision?view=azure-python +[ref_computervision_computervisionerrorexception]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.computervisionerrorexception?view=azure-python +[ref_httpfailure]: https://docs.microsoft.com/python/api/msrest/msrest.exceptions.httpoperationerror?view=azure-python -[computervision_resource]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe +[computervision_resource]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe -[computervision_docs]: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/home +[computervision_docs]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/home -[ref_computervisionclient]: http://computervisionproto.westus.azurecontainer.io/#azure.computervision.computervisionClient +[ref_computervisionclient]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python -[ref_computervisionclient_analyze_image]: https://docs.microsoft.com/en-us/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- -[ref_computervisionclient_list_models]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python#list-models-custom-headers-none--raw-false----operation-config- -[ref_computervisionclient_analyze_image_by_domain]:https://docs.microsoft.com/en-us/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- -[ref_computervisionclient_describe_image]:https://docs.microsoft.com/en-us/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- -[ref_computervisionclient_recognize_text]:https://docs.microsoft.com/en-us/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- -[ref_computervisionclient_get_text_operation_result]:https://docs.microsoft.com/en-us/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- -[ref_computervisionclient_generate_thumbnail]:https://docs.microsoft.com/en-us/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- +[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- +[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- +[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- +[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- +[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- +[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- +[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- -[ref_computervision_model_visualfeatures]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?view=azure-python +[ref_computervision_model_visualfeatures]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?view=azure-python -[ref_computervision_model_textoperationstatuscodes]:https://docs.microsoft.com/en-us/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.textoperationstatuscodes?view=azure-python +[ref_computervision_model_textoperationstatuscodes]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.textoperationstatuscodes?view=azure-python -[computervision_request_units]:https://azure.microsoft.com/en-us/pricing/details/cognitive-services/computer-vision/ +[computervision_request_units]:https://azure.microsoft.com/pricing/details/cognitive-services/computer-vision/ [recognize-text]:https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/computer_vision_samples.py From 57a524acbd1ee9f08e973c3801f53a7fdbd50e43 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Tue, 5 Feb 2019 12:42:00 -0800 Subject: [PATCH 13/24] added pip package reference into install section --- azure-cognitiveservices-vision-computervision/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index a13a62617250..0e56e416e382 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -50,7 +50,7 @@ source cogsrv-vision-env/bin/activate ### Install the SDK -Install the Azure Cognitive Services Computer Vision SDK for Python with [pip][pip]: +Install the Azure Cognitive Services Computer Vision SDK for Python [pip package][pypi_computervision] with [pip][pip]: ```Bash pip install azure-cognitiveservices-vision-computervision From 2e27f60bc2afec35d8f3fd46761887a122340650 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 6 Feb 2019 07:19:46 -0800 Subject: [PATCH 14/24] Larent and Johan's changes --- azure-cognitiveservices-vision-computervision/MANIFEST.in | 2 +- .../sdk_packaging.toml | 1 + azure-cognitiveservices-vision-computervision/setup.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-cognitiveservices-vision-computervision/MANIFEST.in b/azure-cognitiveservices-vision-computervision/MANIFEST.in index bb37a2723dae..efa752eaff96 100644 --- a/azure-cognitiveservices-vision-computervision/MANIFEST.in +++ b/azure-cognitiveservices-vision-computervision/MANIFEST.in @@ -1 +1 @@ -include *.rst +include *.md diff --git a/azure-cognitiveservices-vision-computervision/sdk_packaging.toml b/azure-cognitiveservices-vision-computervision/sdk_packaging.toml index 069c9df58b06..52a5d3275eb3 100644 --- a/azure-cognitiveservices-vision-computervision/sdk_packaging.toml +++ b/azure-cognitiveservices-vision-computervision/sdk_packaging.toml @@ -4,3 +4,4 @@ package_pprint_name = "Cognitive Services Computer Vision" package_doc_id = "cognitive-services" is_stable = false is_arm = false +autoupdate = false diff --git a/azure-cognitiveservices-vision-computervision/setup.py b/azure-cognitiveservices-vision-computervision/setup.py index 500702758cf2..73fa112ae885 100644 --- a/azure-cognitiveservices-vision-computervision/setup.py +++ b/azure-cognitiveservices-vision-computervision/setup.py @@ -53,6 +53,7 @@ version=version, description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), long_description=readme + '\n\n' + history, + long_description_content_type='text/markdown', license='MIT License', author='Microsoft Corporation', author_email='azpysdkhelp@microsoft.com', From d9ae2722434a4a66a8dc74904dc2881fbaece7be Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 6 Feb 2019 07:21:50 -0800 Subject: [PATCH 15/24] edit package link name --- azure-cognitiveservices-vision-computervision/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index 0e56e416e382..ab3a619cedb3 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -50,7 +50,7 @@ source cogsrv-vision-env/bin/activate ### Install the SDK -Install the Azure Cognitive Services Computer Vision SDK for Python [pip package][pypi_computervision] with [pip][pip]: +Install the Azure Cognitive Services Computer Vision SDK for Python [package][pypi_computervision] with [pip][pip]: ```Bash pip install azure-cognitiveservices-vision-computervision From 28deacfea9b8d1cec132afd921f8bbe20b4698ef Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 6 Feb 2019 12:29:04 -0800 Subject: [PATCH 16/24] fixing reference for readme.md --- azure-cognitiveservices-vision-computervision/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-cognitiveservices-vision-computervision/setup.py b/azure-cognitiveservices-vision-computervision/setup.py index 73fa112ae885..956e8ab82689 100644 --- a/azure-cognitiveservices-vision-computervision/setup.py +++ b/azure-cognitiveservices-vision-computervision/setup.py @@ -43,7 +43,7 @@ if not version: raise RuntimeError('Cannot find version information') -with open('README.rst', encoding='utf-8') as f: +with open('README.md', encoding='utf-8') as f: readme = f.read() with open('HISTORY.rst', encoding='utf-8') as f: history = f.read() From f84e0cb600dfe3a07b9886fc34cbbb1814844ade Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 6 Feb 2019 13:06:58 -0800 Subject: [PATCH 17/24] changes based on azure-template/setup.py --- azure-cognitiveservices-vision-computervision/setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azure-cognitiveservices-vision-computervision/setup.py b/azure-cognitiveservices-vision-computervision/setup.py index 956e8ab82689..670d703182e8 100644 --- a/azure-cognitiveservices-vision-computervision/setup.py +++ b/azure-cognitiveservices-vision-computervision/setup.py @@ -52,8 +52,7 @@ name=PACKAGE_NAME, version=version, description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), - long_description=readme + '\n\n' + history, - long_description_content_type='text/markdown', + long_description=readme, license='MIT License', author='Microsoft Corporation', author_email='azpysdkhelp@microsoft.com', From 9c0d30191ad44f143fe934654443eae113c5c25c Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 6 Feb 2019 13:50:59 -0800 Subject: [PATCH 18/24] adding long description back --- azure-cognitiveservices-vision-computervision/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-cognitiveservices-vision-computervision/setup.py b/azure-cognitiveservices-vision-computervision/setup.py index 670d703182e8..944d10244d79 100644 --- a/azure-cognitiveservices-vision-computervision/setup.py +++ b/azure-cognitiveservices-vision-computervision/setup.py @@ -53,6 +53,7 @@ version=version, description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), long_description=readme, + long_description_content_type='text/markdown', license='MIT License', author='Microsoft Corporation', author_email='azpysdkhelp@microsoft.com', From abb9acc6b25f6172933a662a97a2a3d40c2e6357 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Thu, 14 Feb 2019 10:11:39 -0800 Subject: [PATCH 19/24] remove .RST file --- .../README.rst | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 azure-cognitiveservices-vision-computervision/README.rst diff --git a/azure-cognitiveservices-vision-computervision/README.rst b/azure-cognitiveservices-vision-computervision/README.rst deleted file mode 100644 index eee101b4fb52..000000000000 --- a/azure-cognitiveservices-vision-computervision/README.rst +++ /dev/null @@ -1,43 +0,0 @@ -Microsoft Azure SDK for Python -============================== - -This is the Microsoft Azure Cognitive Services Computer Vision Client Library. - -This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7. - -For a more complete set of Azure libraries, see the `azure `__ bundle package. - - -Compatibility -============= - -**IMPORTANT**: If you have an earlier version of the azure package -(version < 1.0), you should uninstall it before installing this package. - -You can check the version using pip: - -.. code:: shell - - pip freeze - -If you see azure==0.11.0 (or any version below 1.0), uninstall it first: - -.. code:: shell - - pip uninstall azure - - -Usage -===== - -For code examples, see `Cognitive Services Computer Vision -`__ -on docs.microsoft.com. - - -Provide Feedback -================ - -If you encounter any bugs or have suggestions, please file an issue in the -`Issues `__ -section of the project. From a4e10623c908ba29353ac530fb4a49cefa257c0b Mon Sep 17 00:00:00 2001 From: Marsh Macy Date: Wed, 27 Feb 2019 16:36:34 -0800 Subject: [PATCH 20/24] convert HISTORY to Markdown --- .../{HISTORY.rst => HISTORY.md} | 27 +++++++------------ .../README.md | 22 ++++++++------- .../setup.py | 4 +-- 3 files changed, 25 insertions(+), 28 deletions(-) rename azure-cognitiveservices-vision-computervision/{HISTORY.rst => HISTORY.md} (89%) diff --git a/azure-cognitiveservices-vision-computervision/HISTORY.rst b/azure-cognitiveservices-vision-computervision/HISTORY.md similarity index 89% rename from azure-cognitiveservices-vision-computervision/HISTORY.rst rename to azure-cognitiveservices-vision-computervision/HISTORY.md index 399421196d94..109b91ebf389 100644 --- a/azure-cognitiveservices-vision-computervision/HISTORY.rst +++ b/azure-cognitiveservices-vision-computervision/HISTORY.md @@ -1,26 +1,22 @@ -.. :changelog: +## Release History -Release History -=============== +### 0.2.0 (2018-06-22) -0.2.0 (2018-06-22) -++++++++++++++++++ - -**Features** +#### Features - analyze_image now support 'en', 'es', 'ja', 'pt', 'zh' (including "in_stream" version of these operations) - describe_image/tag_image/analyze_image_by_domain now support the language parameter (including "in_stream" version of these operations) - Client class can be used as a context manager to keep the underlying HTTP session open for performance -**Bug fixes** +#### Bug fixes - Fix several invalid JSON description, that was raising unexpected exceptions (including OCRResult from bug #2614) -**Breaking changes** +#### Breaking changes - recognize_text "detect_handwriting" boolean is now a "mode" str between 'Handwritten' and 'Printed' -**General Breaking changes** +#### General breaking changes This version uses a next-generation code generator that *might* introduce breaking changes. @@ -29,23 +25,20 @@ This version uses a next-generation code generator that *might* introduce breaki - Enum types now use the "str" mixin (class AzureEnum(str, Enum)) to improve the behavior when unrecognized enum values are encountered. While this is not a breaking change, the distinctions are important, and are documented here: https://docs.python.org/3/library/enum.html#others - At a glance: + At a glance: - "is" should not be used at all. - "format" will return the string value, where "%s" string formatting will return `NameOfEnum.stringvalue`. Format syntax should be prefered. - - New Long Running Operation: - - Return type changes from `msrestazure.azure_operation.AzureOperationPoller` to `msrest.polling.LROPoller`. External API is the same. - Return type is now **always** a `msrest.polling.LROPoller`, regardless of the optional parameters used. - - The behavior has changed when using `raw=True`. Instead of returning the initial call result as `ClientRawResponse`, + - The behavior has changed when using `raw=True`. Instead of returning the initial call result as `ClientRawResponse`, without polling, now this returns an LROPoller. After polling, the final resource will be returned as a `ClientRawResponse`. - New `polling` parameter. The default behavior is `Polling=True` which will poll using ARM algorithm. When `Polling=False`, the response of the initial call will be returned without polling. - `polling` parameter accepts instances of subclasses of `msrest.polling.PollingMethod`. - `add_done_callback` will no longer raise if called after polling is finished, but will instead execute the callback right away. -0.1.0 (2018-01-23) -++++++++++++++++++ +### 0.1.0 (2018-01-23) -* Initial Release +- Initial release diff --git a/azure-cognitiveservices-vision-computervision/README.md b/azure-cognitiveservices-vision-computervision/README.md index ab3a619cedb3..cfc25c82b9a4 100644 --- a/azure-cognitiveservices-vision-computervision/README.md +++ b/azure-cognitiveservices-vision-computervision/README.md @@ -1,6 +1,6 @@ # Azure Cognitive Services Computer Vision SDK for Python -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. For example, Computer Vision can determine if an image contains adult or racy content, find all the faces in an image, get handwritten or printed text. This service works with popular image formats, such as JPEG and PNG. +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. You can use Computer Vision in your application to: @@ -22,7 +22,7 @@ Looking for more documentation? If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command: ```Bash -RES_REGION=westeurope +RES_REGION=westeurope RES_GROUP= ACCT_NAME= @@ -60,7 +60,7 @@ pip install azure-cognitiveservices-vision-computervision Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. -Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient] client object. +Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient] client object. ### Get credentials @@ -104,9 +104,9 @@ client = ComputerVisionAPI(region, credentials) Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client object, you can: -* Analyze an image: You can analyze an image for certain features such as faces, colors, tags. +* Analyze an image: You can analyze an image for certain features such as faces, colors, tags. * Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image. -* Get description of an image: Get a description of the image based on its subject domain. +* Get description of an image: Get a description of the image based on its subject domain. For more information about this service, see [What is Computer Vision?][computervision_docs]. @@ -147,11 +147,11 @@ for x in models.models_property: ### Analyze an image by domain -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. +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. ```Python domain = "landmarks" -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" +url = "https://images.pexels.com/photos/338515/pexels-photo-338515.jpeg" language = "en" analysis = client.analyze_image_by_domain(domain, url, language) @@ -180,9 +180,13 @@ for caption in analysis.captions: ### Get text from image -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. +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. ```Python +# import models +from azure.cognitiveservices.vision.computervision.models import TextRecognitionMode +from azure.cognitiveservices.vision.computervision.models import TextOperationStatusCodes + url = "https://azurecomcdn.azureedge.net/cvt-1979217d3d0d31c5c87cbd991bccfee2d184b55eeb4081200012bdaf6a65601a/images/shared/cognitive-services-demos/read-text/read-1-thumbnail.png" mode = TextRecognitionMode.handwritten raw = True @@ -210,7 +214,7 @@ if result.status == TextOperationStatusCodes.succeeded: ### Generate thumbnail -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. +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. This example uses the [Pillow][pypi_pillow] package to save the new thumbnail image locally. diff --git a/azure-cognitiveservices-vision-computervision/setup.py b/azure-cognitiveservices-vision-computervision/setup.py index 944d10244d79..e87c40cfb41e 100644 --- a/azure-cognitiveservices-vision-computervision/setup.py +++ b/azure-cognitiveservices-vision-computervision/setup.py @@ -45,14 +45,14 @@ with open('README.md', encoding='utf-8') as f: readme = f.read() -with open('HISTORY.rst', encoding='utf-8') as f: +with open('HISTORY.md', encoding='utf-8') as f: history = f.read() setup( name=PACKAGE_NAME, version=version, description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), - long_description=readme, + long_description=readme + '\n\n' + history, long_description_content_type='text/markdown', license='MIT License', author='Microsoft Corporation', From 2936abb0f426bb0e1bb6bd709d5039708cb1eee3 Mon Sep 17 00:00:00 2001 From: Dina Berry Date: Wed, 6 Mar 2019 12:28:04 -0800 Subject: [PATCH 21/24] autoupdate to auto_update --- .../sdk_packaging.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-cognitiveservices-vision-computervision/sdk_packaging.toml b/azure-cognitiveservices-vision-computervision/sdk_packaging.toml index 52a5d3275eb3..1d0d02815221 100644 --- a/azure-cognitiveservices-vision-computervision/sdk_packaging.toml +++ b/azure-cognitiveservices-vision-computervision/sdk_packaging.toml @@ -4,4 +4,4 @@ package_pprint_name = "Cognitive Services Computer Vision" package_doc_id = "cognitive-services" is_stable = false is_arm = false -autoupdate = false +auto_update = false From 370ed8a757d892bf4654830ad3c54dd5b90c96e5 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Tue, 10 Mar 2020 21:11:00 -0700 Subject: [PATCH 22/24] returning mgmt-batch to what it should be --- sdk/batch/azure-mgmt-batch/README.md | 336 ++------------------------- 1 file changed, 18 insertions(+), 318 deletions(-) diff --git a/sdk/batch/azure-mgmt-batch/README.md b/sdk/batch/azure-mgmt-batch/README.md index cfc25c82b9a4..e895f55e3899 100644 --- a/sdk/batch/azure-mgmt-batch/README.md +++ b/sdk/batch/azure-mgmt-batch/README.md @@ -1,329 +1,29 @@ -# Azure Cognitive Services Computer Vision SDK for Python +## Microsoft Azure SDK for Python -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. +This is the Microsoft Azure Batch Management Client Library. -You can use Computer Vision in your application to: +Azure Resource Manager (ARM) is the next generation of management APIs +that replace the old Azure Service Management (ASM). -- Analyze images for insight -- Extract text from images -- Generate thumbnails +This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7. -Looking for more documentation? +For the older Azure Service Management (ASM) libraries, see +[azure-servicemanagement-legacy](https://pypi.python.org/pypi/azure-servicemanagement-legacy) +library. -* [SDK reference documentation](https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision) -* [Cognitive Services Computer Vision documentation](https://docs.microsoft.com/azure/cognitive-services/computer-vision/) - -## Prerequisites - -* Azure subscription - [Create a free account][azure_sub] -* Azure [Computer Vision resource][computervision_resource] -* [Python 3.6+][python] - -If you need a Computer Vision API account, you can create one with this [Azure CLI][azure_cli] command: - -```Bash -RES_REGION=westeurope -RES_GROUP= -ACCT_NAME= - -az cognitiveservices account create \ - --resource-group $RES_GROUP \ - --name $ACCT_NAME \ - --location $RES_REGION \ - --kind ComputerVision \ - --sku S1 \ - --yes -``` - -## Installation - -Install the Azure Cognitive Services Computer Vision SDK with [pip][pip], optionally within a [virtual environment][venv]. - -### Configure a virtual environment (optional) - -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`: - -```Bash -python3 -m venv cogsrv-vision-env -source cogsrv-vision-env/bin/activate -``` - -### Install the SDK - -Install the Azure Cognitive Services Computer Vision SDK for Python [package][pypi_computervision] with [pip][pip]: - -```Bash -pip install azure-cognitiveservices-vision-computervision -``` - -## Authentication - -Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. - -Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient] client object. - -### Get credentials - -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. - -```Bash -RES_GROUP= -ACCT_NAME= - -export ACCOUNT_REGION=$(az cognitiveservices account show \ - --resource-group $RES_GROUP \ - --name $ACCT_NAME \ - --query location \ - --output tsv) - -export ACCOUNT_KEY=$(az cognitiveservices account keys list \ - --resource-group $RES_GROUP \ - --name $ACCT_NAME \ - --query key1 \ - --output tsv) -``` - -### Create client - -Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionAPI][ref_computervisionclient] client object. - -```Python -from azure.cognitiveservices.vision.computervision import ComputerVisionAPI -from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes -from msrest.authentication import CognitiveServicesCredentials - -import os -region = os.environ['ACCOUNT_REGION'] -key = os.environ['ACCOUNT_KEY'] - -credentials = CognitiveServicesCredentials(key) -client = ComputerVisionAPI(region, credentials) -``` +For a more complete set of Azure libraries, see the +[azure](https://pypi.python.org/pypi/azure) bundle package. ## Usage -Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client object, you can: - -* Analyze an image: You can analyze an image for certain features such as faces, colors, tags. -* Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image. -* Get description of an image: Get a description of the image based on its subject domain. - -For more information about this service, see [What is Computer Vision?][computervision_docs]. - -## Examples - -The following sections provide several code snippets covering some of the most common Computer Vision tasks, including: - -* [Analyze an image](#analyze-an-image) -* [Get subject domain list](#get-subject-domain-list) -* [Analyze an image by domain](#analyze-an-image-by-domain) -* [Get text description of an image](#get-text-description-of-an-image) -* [Get handwritten text from image](#get-text-from-image) -* [Generate thumbnail](#generate-thumbnail) - -### Analyze an image - -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`. - -```Python -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" - -image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags]) - -for tag in image_analysis.tags: - print(tag) -``` - -### Get subject domain list - -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`. - -```Python -models = client.list_models() - -for x in models.models_property: - print(x) -``` - -### Analyze an image by domain - -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. - -```Python -domain = "landmarks" -url = "https://images.pexels.com/photos/338515/pexels-photo-338515.jpeg" -language = "en" - -analysis = client.analyze_image_by_domain(domain, url, language) - -for landmark in analysis.result["landmarks"]: - print(landmark["name"]) - print(landmark["confidence"]) -``` - -### Get text description of an image - -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`. - -```Python -domain = "landmarks" -url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" -language = "en" -max_descriptions = 3 - -analysis = client.describe_image(url, max_descriptions, language) - -for caption in analysis.captions: - print(caption.text) - print(caption.confidence) -``` - -### Get text from image - -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. - -```Python -# import models -from azure.cognitiveservices.vision.computervision.models import TextRecognitionMode -from azure.cognitiveservices.vision.computervision.models import TextOperationStatusCodes - -url = "https://azurecomcdn.azureedge.net/cvt-1979217d3d0d31c5c87cbd991bccfee2d184b55eeb4081200012bdaf6a65601a/images/shared/cognitive-services-demos/read-text/read-1-thumbnail.png" -mode = TextRecognitionMode.handwritten -raw = True -custom_headers = None -numberOfCharsInOperationId = 36 - -# SDK call -rawHttpResponse = client.recognize_text(url, mode, custom_headers, raw) - -# Get ID from returned headers -operationLocation = rawHttpResponse.headers["Operation-Location"] -idLocation = len(operationLocation) - numberOfCharsInOperationId -operationId = operationLocation[idLocation:] - -# SDK call -result = client.get_text_operation_result(operationId) - -# Get data -if result.status == TextOperationStatusCodes.succeeded: - - for line in result.recognition_result.lines: - print(line.text) - print(line.bounding_box) -``` - -### Generate thumbnail - -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. - -This example uses the [Pillow][pypi_pillow] package to save the new thumbnail image locally. - -```Python -from PIL import Image -import io - -width = 50 -height = 50 -url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" - -thumbnail = client.generate_thumbnail(width, height, url) - -for x in thumbnail: - image = Image.open(io.BytesIO(x)) - -image.save('thumbnail.jpg') -``` - -## Troubleshooting - -### General - -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. - -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. - -```Python - -domain = "landmarks" -url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg" -language = "en" -max_descriptions = 3 - -try: - analysis = client.describe_image(url, max_descriptions, language) - - for caption in analysis.captions: - print(caption.text) - print(caption.confidence) -except HTTPFailure as e: - if e.status_code == 401: - print("Error unauthorized. Make sure your key and region are correct.") - else: - raise -``` - -### Handle transient errors with retries - -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]. - -## Next steps - -### More sample code - -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: - -* [recognize_text][recognize-text] - -### Additional documentation - -For more extensive documentation on the Computer Vision service, see the [Azure Computer Vision documentation][computervision_docs] on docs.microsoft.com. - - -[pip]: https://pypi.org/project/pip/ -[python]: https://www.python.org/downloads/ - -[azure_cli]: https://docs.microsoft.com/cli/azure -[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker -[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry -[azure_portal]: https://portal.azure.com -[azure_sub]: https://azure.microsoft.com/free/ - -[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview - -[venv]: https://docs.python.org/3/library/venv.html -[virtualenv]: https://virtualenv.pypa.io - -[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-cognitiveservices-vision-computervision - -[pypi_computervision]:https://pypi.org/project/azure-cognitiveservices-vision-computervision/ -[pypi_pillow]:https://pypi.org/project/Pillow/ - -[ref_computervision_sdk]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision?view=azure-python -[ref_computervision_computervisionerrorexception]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.computervisionerrorexception?view=azure-python -[ref_httpfailure]: https://docs.microsoft.com/python/api/msrest/msrest.exceptions.httpoperationerror?view=azure-python - - -[computervision_resource]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/vision-api-how-to-topics/howtosubscribe - -[computervision_docs]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/home - -[ref_computervisionclient]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python - - -[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- -[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- -[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- -[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- -[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- -[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- -[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- - - -[ref_computervision_model_visualfeatures]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?view=azure-python - -[ref_computervision_model_textoperationstatuscodes]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.textoperationstatuscodes?view=azure-python +For code examples, see [Batch +Management](https://docs.microsoft.com/python/api/overview/azure/batch) +on docs.microsoft.com. -[computervision_request_units]:https://azure.microsoft.com/pricing/details/cognitive-services/computer-vision/ +## Provide Feedback -[recognize-text]:https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/computer_vision_samples.py +If you encounter any bugs or have suggestions, please file an issue in +the [Issues](https://github.com/Azure/azure-sdk-for-python/issues) +section of the project. +![image](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-mgmt-batch%2FREADME.png) \ No newline at end of file From 72115e2287f8feef30acfff8da1d0b3af44acd4f Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Wed, 11 Mar 2020 13:13:14 -0700 Subject: [PATCH 23/24] First pass fixing just reading the Readme --- .../README.md | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md b/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md index c91f9ba039e7..dac3d2ba7a7d 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md +++ b/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md @@ -60,7 +60,7 @@ pip install azure-cognitiveservices-vision-computervision Once you create your Computer Vision resource, you need its **region**, and one of its **account keys** to instantiate the client object. -Use these values when you create the instance of the [ComputerVisionAPI][ref_computervisionclient] client object. +Use these values when you create the instance of the [ComputerVisionClient][ref_computervisionclient] client object. ### Get credentials @@ -85,10 +85,10 @@ export ACCOUNT_KEY=$(az cognitiveservices account keys list \ ### Create client -Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionAPI][ref_computervisionclient] client object. +Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionClient][ref_computervisionclient] client object. ```Python -from azure.cognitiveservices.vision.computervision import ComputerVisionAPI +from azure.cognitiveservices.vision.computervision import ComputerVisionClient from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes from msrest.authentication import CognitiveServicesCredentials @@ -97,12 +97,15 @@ region = os.environ['ACCOUNT_REGION'] key = os.environ['ACCOUNT_KEY'] credentials = CognitiveServicesCredentials(key) -client = ComputerVisionAPI(region, credentials) +client = ComputerVisionClient( + endpoint="https://" + region + ".api.cognitive.microsoft.com/", + credentials=credentials +) ``` ## Usage -Once you've initialized a [ComputerVisionAPI][ref_computervisionclient] client object, you can: +Once you've initialized a [ComputerVisionClient][ref_computervisionclient] client object, you can: * Analyze an image: You can analyze an image for certain features such as faces, colors, tags. * Generate thumbnails: Create a custom JPEG image to use as a thumbnail of the original image. @@ -238,7 +241,7 @@ image.save('thumbnail.jpg') ### General -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. +When you interact with the [ComputerVisionClient][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. 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. @@ -264,7 +267,7 @@ except HTTPFailure as e: ### Handle transient errors with retries -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]. +While working with the [ComputerVisionClient][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]. ## Next steps @@ -293,7 +296,7 @@ For more extensive documentation on the Computer Vision service, see the [Azure [venv]: https://docs.python.org/3/library/venv.html [virtualenv]: https://virtualenv.pypa.io -[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-cognitiveservices-vision-computervision +[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision [pypi_computervision]:https://pypi.org/project/azure-cognitiveservices-vision-computervision/ [pypi_pillow]:https://pypi.org/project/Pillow/ @@ -307,16 +310,16 @@ For more extensive documentation on the Computer Vision service, see the [Azure [computervision_docs]: https://docs.microsoft.com/azure/cognitive-services/computer-vision/home -[ref_computervisionclient]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionapi?view=azure-python +[ref_computervisionclient]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python -[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- -[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- -[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- -[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- -[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- -[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- -[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- +[ref_computervisionclient_analyze_image]: https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#analyze-image-url--visual-features-none--details-none--language--en---custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_list_models]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#list-models-custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_analyze_image_by_domain]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#analyze-image-by-domain-model--url--language--en---custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_describe_image]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#describe-image-url--max-candidates--1---language--en---custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_recognize_text]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#recognize-text-url--mode--custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_get_text_operation_result]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#get-text-operation-result-operation-id--custom-headers-none--raw-false----operation-config- +[ref_computervisionclient_generate_thumbnail]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.computervisionclient?view=azure-python#generate-thumbnail-width--height--url--smart-cropping-false--custom-headers-none--raw-false--callback-none----operation-config- [ref_computervision_model_visualfeatures]:https://docs.microsoft.com/python/api/azure-cognitiveservices-vision-computervision/azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?view=azure-python From 2f37c50d8604be87b9a87bcd71122e0af8b208d0 Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Wed, 11 Mar 2020 13:27:29 -0700 Subject: [PATCH 24/24] Fix recognize_text sample --- .../azure-cognitiveservices-vision-computervision/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md b/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md index dac3d2ba7a7d..0956f6eb55b0 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md +++ b/sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md @@ -190,8 +190,8 @@ You can get any handwritten or printed text from an image. This requires two cal from azure.cognitiveservices.vision.computervision.models import TextRecognitionMode from azure.cognitiveservices.vision.computervision.models import TextOperationStatusCodes -url = "https://azurecomcdn.azureedge.net/cvt-1979217d3d0d31c5c87cbd991bccfee2d184b55eeb4081200012bdaf6a65601a/images/shared/cognitive-services-demos/read-text/read-1-thumbnail.png" -mode = TextRecognitionMode.handwritten +url = "https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/raw/master/samples/vision/images/make_things_happen.jpg" +mode = TextRecognitionMode.printed raw = True custom_headers = None numberOfCharsInOperationId = 36