Computer Vision - Java Code sample

The Computer Vision APIs are a collection of state-of-the-art image processing algorithms designed to return information based on the visual content, and to generate your ideal thumbnail. The Computer Vision APIs mainly includes analyzing an image, Generating a thumbnail and OCR.

Here is a sample of the Computer Vision using Java 
to analyze an image.

You can find a testing console along with other code samples in our API reference documentation here.  

// // This sample uses the Apache HTTP client from HTTP Components (
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
    public static void main(String[] args) 
        HttpClient httpclient = HttpClients.createDefault();

            URIBuilder builder = new URIBuilder("");

            builder.setParameter("visualFeatures", "Categories");
            builder.setParameter("details", "{string}");

            URI uri =;
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "application/json");
            request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");

            // Request body
            StringEntity reqEntity = new StringEntity("{body}");

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
        catch (Exception e)

    Feedback and Knowledge Base