Registry /
azure / azure-cognitiveservices-vision-computervision
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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 1.129s · 45.6MB
glibcpy 3.10–3.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}")
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.
fixVerify 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.
fixDouble-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).
fixEnsure 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).
fixVerify 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).