Azure Cognitive Services Computer Vision Client Library (Deprecated)

0.9.1 · deprecated · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →