CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-cognitiveservices-vision-computervision

Microsoft Azure Cognitive Services Computer Vision Client Library for Python providing state-of-the-art algorithms to process images and return information including mature content detection, face detection, color analysis, image categorization, description generation, and thumbnail creation.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

domain-analysis.mddocs/

Domain-Specific Analysis

Specialized image analysis using domain-specific models for celebrity and landmark recognition. These models provide detailed information about famous people and notable landmarks when detected in images.

Capabilities

Celebrity Recognition

Identify famous people in images with confidence scores and face location information.

def analyze_image_by_domain(model, url, language="en", custom_headers=None, raw=False, **operation_config):
    """
    Analyze image using domain-specific model.
    
    Args:
        model (str): Domain model name. Available models:
            - "celebrities": Detect and identify famous people
            - "landmarks": Identify notable landmarks and locations
        url (str): Publicly reachable URL of an image
        language (str, optional): Output language for results. Default: "en"
        custom_headers (dict, optional): Custom HTTP headers
        raw (bool, optional): Return raw response. Default: False
        
    Returns:
        DomainModelResults: Domain-specific analysis results
        
    Raises:
        ComputerVisionErrorResponseException: API error occurred
    """

def analyze_image_by_domain_in_stream(model, image, language="en", custom_headers=None, raw=False, **operation_config):
    """
    Domain-specific analysis from binary image stream.
    
    Args:
        model (str): Domain model name ("celebrities" or "landmarks")
        image (Generator): Binary image data stream
        language (str, optional): Output language
        
    Returns:
        DomainModelResults: Domain-specific analysis results
    """

def list_models(custom_headers=None, raw=False, **operation_config):
    """
    List available domain models.
    
    Returns:
        ListModelsResult: Available domain models with descriptions
        
    Note:
        This endpoint returns information about all available domain-specific models
        including their names and capabilities.
    """

Usage Examples

Celebrity Recognition

from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from msrest.authentication import CognitiveServicesCredentials

# Initialize client
credentials = CognitiveServicesCredentials("your-api-key")
client = ComputerVisionClient("https://your-endpoint.cognitiveservices.azure.com/", credentials)

# Analyze image for celebrities
image_url = "https://example.com/red-carpet-photo.jpg"
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)

# Check if celebrities were detected
if celebrity_results.result and 'celebrities' in celebrity_results.result:
    celebrities = celebrity_results.result['celebrities']
    
    print(f"Detected {len(celebrities)} celebrities:")
    for celebrity in celebrities:
        print(f"\nCelebrity: {celebrity['name']}")
        print(f"Confidence: {celebrity['confidence']:.3f}")
        
        # Face location information
        if 'faceRectangle' in celebrity:
            face_rect = celebrity['faceRectangle']
            print(f"Face location: ({face_rect['left']}, {face_rect['top']}) "
                  f"size: {face_rect['width']}x{face_rect['height']}")
else:
    print("No celebrities detected in the image")

Landmark Recognition

# Analyze image for landmarks
image_url = "https://example.com/tourist-photo.jpg"
landmark_results = client.analyze_image_by_domain("landmarks", image_url)

# Check if landmarks were detected
if landmark_results.result and 'landmarks' in landmark_results.result:
    landmarks = landmark_results.result['landmarks']
    
    print(f"Detected {len(landmarks)} landmarks:")
    for landmark in landmarks:
        print(f"\nLandmark: {landmark['name']}")
        print(f"Confidence: {landmark['confidence']:.3f}")
        
        # Additional landmark information
        if 'description' in landmark:
            print(f"Description: {landmark['description']}")
        
        if 'location' in landmark:
            location = landmark['location']
            print(f"Location: {location.get('name', 'Unknown')}")
            
else:
    print("No landmarks detected in the image")

Available Models Query

# List all available domain models
models_result = client.list_models()

print("Available domain models:")
for model in models_result.models_property:
    print(f"\nModel: {model.name}")
    if hasattr(model, 'categories') and model.categories:
        print(f"Categories: {', '.join(model.categories)}")
    if hasattr(model, 'description') and model.description:
        print(f"Description: {model.description}")

Combined Celebrity and Landmark Analysis

# Analyze the same image with both models
image_url = "https://example.com/event-photo.jpg"

print("Analyzing image with multiple domain models...")

# Celebrity analysis
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)
celebrities_found = 0
if celebrity_results.result and 'celebrities' in celebrity_results.result:
    celebrities_found = len(celebrity_results.result['celebrities'])

# Landmark analysis  
landmark_results = client.analyze_image_by_domain("landmarks", image_url)
landmarks_found = 0
if landmark_results.result and 'landmarks' in landmark_results.result:
    landmarks_found = len(landmark_results.result['landmarks'])

print(f"\nAnalysis Summary:")
print(f"Celebrities detected: {celebrities_found}")
print(f"Landmarks detected: {landmarks_found}")

# Detailed results
if celebrities_found > 0:
    print(f"\nCelebrities:")
    for celebrity in celebrity_results.result['celebrities']:
        print(f"  - {celebrity['name']} (confidence: {celebrity['confidence']:.3f})")

if landmarks_found > 0:
    print(f"\nLandmarks:")
    for landmark in landmark_results.result['landmarks']:
        print(f"  - {landmark['name']} (confidence: {landmark['confidence']:.3f})")

Local File Domain Analysis

# Analyze local image file for celebrities
with open("party_photo.jpg", "rb") as image_stream:
    celebrity_results = client.analyze_image_by_domain_in_stream(
        "celebrities", 
        image_stream
    )
    
    if celebrity_results.result and 'celebrities' in celebrity_results.result:
        for celebrity in celebrity_results.result['celebrities']:
            print(f"Found: {celebrity['name']} (confidence: {celebrity['confidence']:.3f})")
    else:
        print("No celebrities detected in local image")

Batch Domain Analysis

# Process multiple images for celebrity detection
image_urls = [
    "https://example.com/movie-premiere1.jpg",
    "https://example.com/movie-premiere2.jpg",
    "https://example.com/award-show.jpg"
]

all_celebrities = set()

for i, url in enumerate(image_urls, 1):
    try:
        print(f"Processing image {i}/{len(image_urls)}...")
        
        celebrity_results = client.analyze_image_by_domain("celebrities", url)
        
        if celebrity_results.result and 'celebrities' in celebrity_results.result:
            image_celebrities = celebrity_results.result['celebrities']
            print(f"  Found {len(image_celebrities)} celebrities")
            
            for celebrity in image_celebrities:
                all_celebrities.add(celebrity['name'])
                print(f"    - {celebrity['name']} (confidence: {celebrity['confidence']:.3f})")
        else:
            print("  No celebrities detected")
            
    except Exception as e:
        print(f"  Error processing image: {e}")

print(f"\nUnique celebrities across all images: {len(all_celebrities)}")
for name in sorted(all_celebrities):
    print(f"  - {name}")

High-Confidence Domain Analysis

# Filter domain analysis results by confidence threshold
image_url = "https://example.com/group-photo.jpg"
confidence_threshold = 0.8

# Celebrity analysis with confidence filtering
celebrity_results = client.analyze_image_by_domain("celebrities", image_url)

high_confidence_celebrities = []
if celebrity_results.result and 'celebrities' in celebrity_results.result:
    high_confidence_celebrities = [
        celebrity for celebrity in celebrity_results.result['celebrities']
        if celebrity['confidence'] >= confidence_threshold
    ]

print(f"High-confidence celebrity detections (≥{confidence_threshold}):")
if high_confidence_celebrities:
    for celebrity in high_confidence_celebrities:
        print(f"  {celebrity['name']}: {celebrity['confidence']:.3f}")
else:
    print("  None found above threshold")

# Show all detections for comparison
if celebrity_results.result and 'celebrities' in celebrity_results.result:
    all_celebrities = celebrity_results.result['celebrities']
    low_confidence = [c for c in all_celebrities if c['confidence'] < confidence_threshold]
    
    if low_confidence:
        print(f"\nLower confidence detections:")
        for celebrity in low_confidence:
            print(f"  {celebrity['name']}: {celebrity['confidence']:.3f}")

Response Data Types

DomainModelResults

class DomainModelResults:
    """
    Domain-specific analysis results.
    
    Attributes:
        result (dict): Domain model results containing detected entities
            For celebrities: {'celebrities': [{'name': str, 'confidence': float, 'faceRectangle': dict}]}
            For landmarks: {'landmarks': [{'name': str, 'confidence': float, 'description': str}]}
        request_id (str): Request identifier
        metadata (ImageMetadata): Image metadata (dimensions, format)
        model_version (str): Domain model version used
    """

ListModelsResult

class ListModelsResult:
    """
    Available domain models listing.
    
    Attributes:
        models_property (list[ModelDescription]): List of available domain models
    """

ModelDescription

class ModelDescription:
    """
    Description of a domain model.
    
    Attributes:
        name (str): Model name (e.g., "celebrities", "landmarks")
        categories (list[str], optional): Model categories or capabilities
        description (str, optional): Model description and use cases
    """

Domain Model Details

Celebrity Model

Capabilities:

  • Recognizes thousands of well-known celebrities from entertainment, sports, politics, and business
  • Provides confidence scores for identity matches
  • Returns face bounding rectangle coordinates
  • Works with partial face visibility and various angles

Celebrity Result Structure:

{
    'celebrities': [
        {
            'name': 'Celebrity Name',
            'confidence': 0.95,
            'faceRectangle': {
                'left': 100,
                'top': 150,
                'width': 80,
                'height': 80
            }
        }
    ]
}

Landmark Model

Capabilities:

  • Identifies famous landmarks, monuments, and buildings worldwide
  • Recognizes natural landmarks like mountains, lakes, and geological formations
  • Provides location context and descriptions
  • Works with various viewing angles and partial views

Landmark Result Structure:

{
    'landmarks': [
        {
            'name': 'Landmark Name',
            'confidence': 0.88,
            'description': 'Brief description of the landmark',
            'location': {
                'name': 'City, Country'
            }
        }
    ]
}

Best Practices

Celebrity Detection

  • Works best with clear, frontal face views
  • Can detect celebrities in group photos
  • Confidence scores above 0.7 are generally reliable
  • May not detect celebrities in heavy makeup, costumes, or significant aging

Landmark Detection

  • Requires recognizable architectural or natural features
  • Works with various weather conditions and lighting
  • Best results with iconic views and clear visibility
  • May struggle with heavily modified or partially obscured landmarks

General Tips

  • Use appropriate confidence thresholds for your application
  • Combine with general image analysis for comprehensive results
  • Consider privacy implications when processing images with people
  • Cache results for frequently analyzed images to improve performance

Install with Tessl CLI

npx tessl i tessl/pypi-azure-cognitiveservices-vision-computervision

docs

area-of-interest.md

domain-analysis.md

image-analysis.md

image-description.md

image-tagging.md

index.md

object-detection.md

ocr-text-recognition.md

thumbnail-generation.md

tile.json