Azure AI Vision Image Analysis Client Library

1.0.0 · active · verified Wed Apr 15

The `azure-ai-vision-imageanalysis` library is Microsoft's client library for Python, providing AI algorithms to process images and extract visual features such as captions, text (OCR), and detected objects. It is currently at version 1.0.0 and follows the Azure SDK's typical release cadence, with continuous improvements and feature additions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with an Azure AI Vision Image Analysis resource using an API key and analyze an image from a URL to generate a caption and extract tags. Ensure `VISION_ENDPOINT` and `VISION_KEY` environment variables are set with your resource's endpoint and API key.

import os
from azure.ai.vision.imageanalysis import ImageAnalysisClient
from azure.ai.vision.imageanalysis.models import VisualFeatures
from azure.core.credentials import AzureKeyCredential

# Set environment variables or replace with actual values
# For authentication with AzureKeyCredential
vision_endpoint = os.environ.get('VISION_ENDPOINT', 'YOUR_VISION_ENDPOINT')
vision_key = os.environ.get('VISION_KEY', 'YOUR_VISION_KEY')

# For authentication with DefaultAzureCredential (uncomment and configure if needed)
# from azure.identity import DefaultAzureCredential
# credential = DefaultAzureCredential()

# Authenticate the client
# Using AzureKeyCredential (most common for quickstarts)
credential = AzureKeyCredential(vision_key)
client = ImageAnalysisClient(endpoint=vision_endpoint, credential=credential)

# Image to analyze
image_url = "https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png"

print("Analyzing image from URL...")

# Analyze the image for a caption
result = client.analyze_from_url(
    image_url,
    visual_features=[VisualFeatures.CAPTION, VisualFeatures.TAGS]
)

if result.caption is not None:
    print(f" Caption: '{result.caption.text}' (confidence: {result.caption.confidence:.2f})")

if result.tags is not None:
    print(" Tags:")
    for tag in result.tags.list:
        print(f"   '{tag.name}' (confidence: {tag.confidence:.2f})")

view raw JSON →