Skip to content

Latest commit

 

History

History
157 lines (109 loc) · 6.34 KB

File metadata and controls

157 lines (109 loc) · 6.34 KB
title description author manager ms.service ms.topic ms.date ms.custom ms.author
Quickstart: Image Analysis client library for Java
In this quickstart, get started with the Image Analysis client library for Java.
PatrickFarley
nitinme
azure-ai-vision
include
12/15/2020
devx-track-java
pafarley

Use the Image Analysis client library to analyze a remote image for tags, text description, faces, adult content, and more.

Tip

You can also analyze a local image. See the ComputerVision methods, such as AnalyzeImage. Or, see the sample code on GitHub for scenarios involving local images.

Tip

The Analyze API can do many different operations other than generate image tags. See the Image Analysis how-to guide for examples that showcase all of the available features.

Reference documentation | Library source code |Artifact (Maven) | Samples

Prerequisites

  • An Azure subscription - Create one for free
  • The current version of the Java Development Kit (JDK)
  • The Gradle build tool, or another dependency manager.
  • Once you have your Azure subscription, create a Vision resource in the Azure portal to get your key and endpoint. After it deploys, select Go to resource.
    • You need the key and endpoint from the resource you create to connect your application to the Azure AI Vision service.
    • You can use the free pricing tier (F0) to try the service, and upgrade later to a paid tier for production.

[!INCLUDE create environment variables]

Analyze image

  1. Create a new Gradle project.

    In a console window (such as cmd, PowerShell, or Bash), create a new directory for your app, and navigate to it.

    mkdir myapp && cd myapp

    Run the gradle init command from your working directory. This command will create essential build files for Gradle, including build.gradle.kts, which is used at runtime to create and configure your application.

    gradle init --type basic

    When prompted to choose a DSL, select Kotlin.

  2. Install the client library.

    This quickstart uses the Gradle dependency manager. You can find the client library and information for other dependency managers on the Maven Central Repository.

    Locate build.gradle.kts and open it with your preferred IDE or text editor. Then copy in the following build configuration. This configuration defines the project as a Java application whose entry point is the class ImageAnalysisQuickstart. It imports the Azure AI Vision library.

    plugins {
        java
        application
    }
    application { 
        mainClass.set("ImageAnalysisQuickstart")
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        implementation(group = "com.microsoft.azure.cognitiveservices", name = "azure-cognitiveservices-computervision", version = "1.0.9-beta")
    }
  3. Create a Java file.

    From your working directory, run the following command to create a project source folder:

    mkdir -p src/main/java

    Navigate to the new folder and create a file called ImageAnalysisQuickstart.java.

  4. Open ImageAnalysisQuickstart.java in your preferred editor or IDE and paste in the following code.

    [!code-java]

  5. Navigate back to the project root folder, and build the app with:

    gradle build

    Then, run it with the gradle run command:

    gradle run

Output

Azure AI Vision - Java Quickstart Sample

Analyzing an image from a URL ...

Tags:
'person' with confidence 0.998895
'human face' with confidence 0.997437
'smile' with confidence 0.991973
'outdoor' with confidence 0.985962
'happy' with confidence 0.969785
'clothing' with confidence 0.961570
'friendship' with confidence 0.946441
'tree' with confidence 0.917331
'female person' with confidence 0.890976
'girl' with confidence 0.888741
'social group' with confidence 0.872044
'posing' with confidence 0.865493
'adolescent' with confidence 0.857371
'love' with confidence 0.852553
'laugh' with confidence 0.850097
'people' with confidence 0.849922
'lady' with confidence 0.844540
'woman' with confidence 0.818172
'group' with confidence 0.792975
'wedding' with confidence 0.615252
'dress' with confidence 0.517169

Clean up resources

If you want to clean up and remove an Azure AI services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it.

Next steps

In this quickstart, you learned how to install the Image Analysis client library and make basic image analysis calls. Next, learn more about the Analyze API features.

[!div class="nextstepaction"] Call the Analyze API