Agent Skillsmicrosoft/skills › azure-ai-vision-imageanalysis-java

azure-ai-vision-imageanalysis-java

GitHub

提供Azure AI Vision图像分析SDK的Java集成指南,涵盖安装、客户端创建及OCR、对象检测等核心功能实现。

.github/plugins/azure-sdk-java/skills/azure-ai-vision-imageanalysis-java/SKILL.md microsoft/skills

Trigger Scenarios

需要调用Azure AI Vision进行图像分析 实现图片OCR文字提取或对象检测 生成图片描述或智能裁剪

Install

npx skills add microsoft/skills --skill azure-ai-vision-imageanalysis-java -g -y
More Options

Non-standard path

npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-java/skills/azure-ai-vision-imageanalysis-java -g -y

Use without installing

npx skills use microsoft/skills@azure-ai-vision-imageanalysis-java

指定 Agent (Claude Code)

npx skills add microsoft/skills --skill azure-ai-vision-imageanalysis-java -a claude-code -g -y

安装 repo 全部 skill

npx skills add microsoft/skills --all -g -y

预览 repo 内 skill

npx skills add microsoft/skills --list

SKILL.md

Frontmatter
{
    "name": "azure-ai-vision-imageanalysis-java",
    "license": "MIT",
    "metadata": {
        "author": "Microsoft",
        "package": "com.azure:azure-ai-vision-imageanalysis",
        "version": "1.0.0"
    },
    "description": "Build image analysis applications with Azure AI Vision SDK for Java. Use when implementing image captioning, OCR text extraction, object detection, tagging, or smart cropping."
}

Azure AI Vision Image Analysis SDK for Java

Build image analysis applications using the Azure AI Vision Image Analysis SDK for Java.

Installation

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-ai-vision-imageanalysis</artifactId>
    <version>1.1.0-beta.1</version>
</dependency>

Client Creation

With API Key

import com.azure.ai.vision.imageanalysis.ImageAnalysisClient;
import com.azure.ai.vision.imageanalysis.ImageAnalysisClientBuilder;
import com.azure.core.credential.KeyCredential;

String endpoint = System.getenv("VISION_ENDPOINT");
String key = System.getenv("VISION_KEY");

ImageAnalysisClient client = new ImageAnalysisClientBuilder()
    .endpoint(endpoint)
    .credential(new KeyCredential(key))
    .buildClient();

Async Client

import com.azure.ai.vision.imageanalysis.ImageAnalysisAsyncClient;

ImageAnalysisAsyncClient asyncClient = new ImageAnalysisClientBuilder()
    .endpoint(endpoint)
    .credential(new KeyCredential(key))
    .buildAsyncClient();

With DefaultAzureCredential

import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureIdentityEnvVars;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;

TokenCredential credential = new DefaultAzureCredentialBuilder()
    .requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)
    .build();
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();

ImageAnalysisClient client = new ImageAnalysisClientBuilder()
    .endpoint(endpoint)
    .credential(credential)
    .buildClient();

Visual Features

Feature Description
CAPTION Generate human-readable image description
DENSE_CAPTIONS Captions for up to 10 regions
READ OCR - Extract text from images
TAGS Content tags for objects, scenes, actions
OBJECTS Detect objects with bounding boxes
SMART_CROPS Smart thumbnail regions
PEOPLE Detect people with locations

Core Patterns

Generate Caption

import com.azure.ai.vision.imageanalysis.models.*;
import com.azure.core.util.BinaryData;
import java.io.File;
import java.util.Arrays;

// From file
BinaryData imageData = BinaryData.fromFile(new File("image.jpg").toPath());

ImageAnalysisResult result = client.analyze(
    imageData,
    Arrays.asList(VisualFeatures.CAPTION),
    new ImageAnalysisOptions().setGenderNeutralCaption(true));

System.out.printf("Caption: \"%s\" (confidence: %.4f)%n",
    result.getCaption().getText(),
    result.getCaption().getConfidence());

Generate Caption from URL

ImageAnalysisResult result = client.analyzeFromUrl(
    "https://example.com/image.jpg",
    Arrays.asList(VisualFeatures.CAPTION),
    new ImageAnalysisOptions().setGenderNeutralCaption(true));

System.out.printf("Caption: \"%s\"%n", result.getCaption().getText());

Extract Text (OCR)

ImageAnalysisResult result = client.analyze(
    BinaryData.fromFile(new File("document.jpg").toPath()),
    Arrays.asList(VisualFeatures.READ),
    null);

for (DetectedTextBlock block : result.getRead().getBlocks()) {
    for (DetectedTextLine line : block.getLines()) {
        System.out.printf("Line: '%s'%n", line.getText());
        System.out.printf("  Bounding polygon: %s%n", line.getBoundingPolygon());
        
        for (DetectedTextWord word : line.getWords()) {
            System.out.printf("  Word: '%s' (confidence: %.4f)%n",
                word.getText(),
                word.getConfidence());
        }
    }
}

Detect Objects

ImageAnalysisResult result = client.analyzeFromUrl(
    imageUrl,
    Arrays.asList(VisualFeatures.OBJECTS),
    null);

for (DetectedObject obj : result.getObjects()) {
    System.out.printf("Object: %s (confidence: %.4f)%n",
        obj.getTags().get(0).getName(),
        obj.getTags().get(0).getConfidence());
    
    ImageBoundingBox box = obj.getBoundingBox();
    System.out.printf("  Location: x=%d, y=%d, w=%d, h=%d%n",
        box.getX(), box.getY(), box.getWidth(), box.getHeight());
}

Get Tags

ImageAnalysisResult result = client.analyzeFromUrl(
    imageUrl,
    Arrays.asList(VisualFeatures.TAGS),
    null);

for (DetectedTag tag : result.getTags()) {
    System.out.printf("Tag: %s (confidence: %.4f)%n",
        tag.getName(),
        tag.getConfidence());
}

Detect People

ImageAnalysisResult result = client.analyzeFromUrl(
    imageUrl,
    Arrays.asList(VisualFeatures.PEOPLE),
    null);

for (DetectedPerson person : result.getPeople()) {
    ImageBoundingBox box = person.getBoundingBox();
    System.out.printf("Person at x=%d, y=%d (confidence: %.4f)%n",
        box.getX(), box.getY(), person.getConfidence());
}

Smart Cropping

ImageAnalysisResult result = client.analyzeFromUrl(
    imageUrl,
    Arrays.asList(VisualFeatures.SMART_CROPS),
    new ImageAnalysisOptions().setSmartCropsAspectRatios(Arrays.asList(1.0, 1.5)));

for (CropRegion crop : result.getSmartCrops()) {
    System.out.printf("Crop region: aspect=%.2f, x=%d, y=%d, w=%d, h=%d%n",
        crop.getAspectRatio(),
        crop.getBoundingBox().getX(),
        crop.getBoundingBox().getY(),
        crop.getBoundingBox().getWidth(),
        crop.getBoundingBox().getHeight());
}

Dense Captions

ImageAnalysisResult result = client.analyzeFromUrl(
    imageUrl,
    Arrays.asList(VisualFeatures.DENSE_CAPTIONS),
    new ImageAnalysisOptions().setGenderNeutralCaption(true));

for (DenseCaption caption : result.getDenseCaptions()) {
    System.out.printf("Caption: \"%s\" (confidence: %.4f)%n",
        caption.getText(),
        caption.getConfidence());
    System.out.printf("  Region: x=%d, y=%d, w=%d, h=%d%n",
        caption.getBoundingBox().getX(),
        caption.getBoundingBox().getY(),
        caption.getBoundingBox().getWidth(),
        caption.getBoundingBox().getHeight());
}

Multiple Features

ImageAnalysisResult result = client.analyzeFromUrl(
    imageUrl,
    Arrays.asList(
        VisualFeatures.CAPTION,
        VisualFeatures.TAGS,
        VisualFeatures.OBJECTS,
        VisualFeatures.READ),
    new ImageAnalysisOptions()
        .setGenderNeutralCaption(true)
        .setLanguage("en"));

// Access all results
System.out.println("Caption: " + result.getCaption().getText());
System.out.println("Tags: " + result.getTags().size());
System.out.println("Objects: " + result.getObjects().size());
System.out.println("Text blocks: " + result.getRead().getBlocks().size());

Async Analysis

asyncClient.analyzeFromUrl(
    imageUrl,
    Arrays.asList(VisualFeatures.CAPTION),
    null)
    .subscribe(
        result -> System.out.println("Caption: " + result.getCaption().getText()),
        error -> System.err.println("Error: " + error.getMessage()),
        () -> System.out.println("Complete")
    );

Error Handling

import com.azure.core.exception.HttpResponseException;

try {
    client.analyzeFromUrl(imageUrl, Arrays.asList(VisualFeatures.CAPTION), null);
} catch (HttpResponseException e) {
    System.out.println("Status: " + e.getResponse().getStatusCode());
    System.out.println("Error: " + e.getMessage());
}

Environment Variables

VISION_ENDPOINT=https://<resource>.cognitiveservices.azure.com/ # Required for all auth methods
VISION_KEY=<your-api-key> # Only required for AzureKeyCredential auth
AZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production

Image Requirements

  • Formats: JPEG, PNG, GIF, BMP, WEBP, ICO, TIFF, MPO
  • Size: < 20 MB
  • Dimensions: 50x50 to 16000x16000 pixels

Regional Availability

Caption and Dense Captions require GPU-supported regions. Check supported regions before deployment.

Trigger Phrases

  • "image analysis Java"
  • "Azure Vision SDK"
  • "image captioning"
  • "OCR image text extraction"
  • "object detection image"
  • "smart crop thumbnail"
  • "detect people image"

Version History

  • 4f1db7e Current 2026-07-25 06:28

Same Skill Collection

.github/plugins/azure-kusto-graph-skills/skills/azure-kusto-irql/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-agents-persistent-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-document-intelligence-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-openai-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-projects-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-ai-voicelive-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-eventgrid-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-eventhub-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-identity-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-maps-search-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apicenter-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apimanagement-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-applicationinsights-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-arizeaiobservabilityeval-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-botservice-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-fabric-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-mongodbatlas-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-weightsandbiases-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-cosmosdb-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-durabletask-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-mysql-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-postgresql-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-redis-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-sql-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-search-documents-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-security-keyvault-keys-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/azure-servicebus-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/m365-agents-dotnet/SKILL.md
.github/plugins/azure-sdk-dotnet/skills/microsoft-azure-webjobs-extensions-authentication-events-dotnet/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-agents-persistent-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-anomalydetector-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-contentsafety-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-formrecognizer-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-projects-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-ai-voicelive-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-appconfiguration-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-callautomation-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-callingserver-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-chat-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-common-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-communication-sms-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-compute-batch-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-cosmos-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-data-tables-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-eventgrid-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-eventhub-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-identity-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-messaging-webpubsub-java/SKILL.md
.github/plugins/azure-sdk-java/skills/azure-monitor-ingestion-java/SKILL.md

Metadata

Files
0
Version
a3d788b
Hash
ea209e06
Indexed
2026-07-25 06:28

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 08:26
浙ICP备14020137号-1 $Гость$