Registry / azure / azure-cognitiveservices-vision-computervision

azure-cognitiveservices-vision-computervision

JSON →
library0.9.1pypiunverified

This is a deprecated Python client library for Microsoft Azure Cognitive Services Computer Vision, offering algorithms for image analysis, OCR, and other vision tasks. The current version is 0.9.1. This package is no longer actively maintained and has been superseded by `azure-ai-vision-imageanalysis`. Users are strongly encouraged to migrate to the new library for continued feature updates and non-security bug fixes.

pip install azure-cognitiveservices-vision-computervision pillow
INSTALL
IMPORT
SIG · AZURE-COGNITIVESER
A
azure-cognitiveservices-vision-computervision
azureenv0.9.1
Install
3.3s avg
Import
1061ms
Disk
44MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 1.129s · 45.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.3s · import 0.993s · 47MB
44MB installed
● package 44MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ComputerVisionClient
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
CognitiveServicesCredentials
from msrest.authentication import CognitiveServicesCredentials
VisualFeatureTypes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from azure.cognitiveservices.vision.computervision import VisualFeatureTypes
VisualFeatureTypes is part of the 'models' submodule.

This quickstart demonstrates how to instantiate the `ComputerVisionClient` and perform a basic image analysis operation on a remote image, extracting its description, tags, and categories. Ensure `VISION_KEY` and `VISION_ENDPOINT` environment variables are set with your Azure Computer Vision resource credentials.

import os from azure.cognitiveservices.vision.computervision import ComputerVisionClient from msrest.authentication import CognitiveServicesCredentials from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes # Set up your Computer Vision subscription key and endpoint as environment variables VISION_KEY = os.environ.get('VISION_KEY', 'YOUR_VISION_SUBSCRIPTION_KEY') VISION_ENDPOINT = os.environ.get('VISION_ENDPOINT', 'YOUR_VISION_ENDPOINT') if not VISION_KEY or not VISION_ENDPOINT: print("Please set the VISION_KEY and VISION_ENDPOINT environment variables.") exit() # Authenticate the client credentials = CognitiveServicesCredentials(VISION_KEY) computervision_client = ComputerVisionClient(VISION_ENDPOINT, credentials) # Analyze a remote image remote_image_url = "https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png" print(f"\nAnalyzing image from URL: {remote_image_url}") # Select the visual features to analyze image_features = [VisualFeatureTypes.categories, VisualFeatureTypes.description, VisualFeatureTypes.tags] analyzed_results = computervision_client.analyze_image(remote_image_url, image_features) # Print results print("Description:") if analyzed_results.description.captions: for caption in analyzed_results.description.captions: print(f" '{caption.text}' with confidence {caption.confidence:.2f}") print("Tags:") if analyzed_results.tags: for tag in analyzed_results.tags: print(f" '{tag.name}' with confidence {tag.confidence:.2f}") print("Categories:") if analyzed_results.categories: for category in analyzed_results.categories: print(f" '{category.name}' with confidence {category.score:.2f}")
Debug
Known issues
breakingThis library (`azure-cognitiveservices-vision-computervision`) has been deprecated. It stopped receiving new features and non-security bug fixes after November 1, 2024, and will only receive security fixes until that date. All users should migrate to the replacement package, `azure-ai-vision-imageanalysis` (Track 2 SDK).
fix
Migrate your code to use `azure-ai-vision-imageanalysis`. Consult the official Azure SDK for Python documentation and migration guides for the new Track 2 SDK patterns.
affects: <=0.9.1
breakingOlder Computer Vision API versions (v1.0, v2.0, v2.1, v3.0, and v3.1) will be retired on September 13, 2026. This SDK uses these older API versions. After this date, API calls to these versions will fail.
fix
Migrate your workloads to Computer Vision v3.2 API or newer. The replacement `azure-ai-vision-imageanalysis` package targets newer API versions.
affects: <=0.9.1
gotchaClient authentication requires using the correct regional endpoint URL that matches your Azure Computer Vision resource, not a global endpoint. Mismatched keys/endpoints are a common source of 401 errors.
fix
Always retrieve both the `VISION_KEY` and `VISION_ENDPOINT` directly from the 'Keys and Endpoint' section of your Computer Vision resource in the Azure portal and ensure they are used together. For example: `https://<your-resource-name>.cognitiveservices.azure.com/`.
affects: *
gotchaEarlier versions (e.g., 0.2.0) introduced breaking changes by switching to keyword-only arguments for model signatures. Later changes also affected how enum types behave (using `str` mixin).
fix
Always refer to the specific version's documentation. When upgrading from older versions, explicitly convert positional arguments to keyword arguments. Be aware of `enum` type comparison changes.
affects: 0.2.0 - 0.9.1
Errors
Common errors & fixes
azure.cognitiveservices.vision.computervision.models._models_py3.ComputerVisionErrorResponseException: (PermissionDenied) Access denied due to invalid subscription key or wrong API endpoint.
The provided subscription key is invalid, expired, or does not match the regional endpoint being used.
fix
Verify that your `VISION_KEY` and `VISION_ENDPOINT` environment variables (or hardcoded values, though not recommended) are correct and correspond to an active Azure Computer Vision resource. Ensure the endpoint URL exactly matches the region where the resource was deployed.
azure.cognitiveservices.vision.computervision.models._models_py3.ComputerVisionErrorResponseException: (ResourceNotFound) Resource not found.
The endpoint URL is incorrect, the resource does not exist, or the API path/version in the URL is unsupported for your resource.
fix
Double-check the `VISION_ENDPOINT` URL for typos. Confirm the Azure Computer Vision resource is active in the portal. Ensure the API version and path being called are valid for your resource and match the endpoint.
azure.cognitiveservices.vision.computervision.models._models_py3.ComputerVisionErrorResponseException: (InvalidImageSize) Image must be at least 50 pixels in width and height.
The input image dimensions (width or height) are smaller than the minimum required size, or the image file size exceeds the allowed limit (e.g., 4MB for v3.2, 20MB for v4.0).
fix
Ensure that images are at least 50x50 pixels. Check the file size against the API limits. For local images, consider resizing or compressing before sending.
azure.cognitiveservices.vision.computervision.models._models_py3.ComputerVisionErrorResponseException: (InvalidImageFormat) Input data is not a valid image.
The provided image data is corrupted, in an unsupported format, or the URL provided for a remote image does not link directly to an image file (e.g., it's a redirect or a webpage).
fix
Verify the image file integrity and format (e.g., JPG, PNG, BMP). If using a URL, ensure it's a direct link to the image file, not a redirect or a webpage containing the image. For local files, ensure the file stream is correctly passed.
Upgrade
Version history
0.9.1latest on PyPI · released Nov 1, 2024
Audit
Dependencies
pillowoptionalRequired for local image processing, especially for stream-based operations.
msrestrequiredUsed for authentication credentials (CognitiveServicesCredentials).
Agent activity
38 hits · last 30 days
node
32
OpenAI (training)
1
Resources
azure-cognitiveservices-vision-computervision — pip install azure-cognitiveservices-vision-computervision · libregistry