Skip to content

Commit 2c40b61

Browse files
authored
Merge pull request #88302 from itechedit/vision-api-how-to-topics
edit pass: Two Vision API how-to articles
2 parents d1914c9 + e8025d1 commit 2c40b61

File tree

2 files changed

+112
-97
lines changed

2 files changed

+112
-97
lines changed

articles/cognitive-services/Computer-vision/Vision-API-How-to-Topics/HowToCallVisionAPI.md

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Example: Call the Analyze image API - Computer Vision"
2+
title: Call the Computer Vision API
33
titleSuffix: Azure Cognitive Services
4-
description: Learn how to call the Computer Vision API by using REST in Azure Cognitive Services.
4+
description: Learn how to call the Computer Vision API by using the REST API in Azure Cognitive Services.
55
services: cognitive-services
66
author: KellyDF
77
manager: nitinme
@@ -14,46 +14,54 @@ ms.author: kefre
1414
ms.custom: seodec18
1515
---
1616

17-
# Example: How to call the Computer Vision API
17+
# Call the Computer Vision API
1818

19-
This guide demonstrates how to call Computer Vision API using REST. The samples are written both in C# using the Computer Vision API client library, and as HTTP POST/GET calls. We will focus on:
19+
This article demonstrates how to call the Computer Vision API by using the REST API. The samples are written both in C# by using the Computer Vision API client library and as HTTP POST or GET calls. The article focuses on:
2020

21-
- How to get "Tags", "Description" and "Categories".
22-
- How to get "Domain-specific" information (celebrities).
21+
- Getting tags, a description, and categories
22+
- Getting domain-specific information, or "celebrities"
2323

2424
## Prerequisites
2525

26-
- Image URL or path to locally stored image.
27-
- Supported input methods: Raw image binary in the form of an application/octet stream or image URL
28-
- Supported image formats: JPEG, PNG, GIF, BMP
29-
- Image file size: Less than 4MB
30-
- Image dimension: Greater than 50 x 50 pixels
26+
- An image URL or a path to a locally stored image
27+
- Supported input methods: a raw image binary in the form of an application/octet-stream, or an image URL
28+
- Supported image file formats: JPEG, PNG, GIF, and BMP
29+
- Image file size: 4 MB or less
30+
- Image dimensions: 50 × 50 pixels or greater
3131

32-
In the examples below, the following features are demonstrated:
32+
The examples in this article demonstrate the following features:
3333

34-
1. Analyzing an image and getting an array of tags and a description returned.
35-
2. Analyzing an image with a domain-specific model (specifically, "celebrities" model) and getting the corresponding result in JSON retune.
34+
* Analyzing an image to return an array of tags and a description
35+
* Analyzing an image with a domain-specific model (specifically, the "celebrities" model) to return the corresponding result in JSON
3636

37-
Features are broken down on:
37+
The features offer the following options:
3838

39-
- **Option One:** Scoped Analysis - Analyze only a given model
40-
- **Option Two:** Enhanced Analysis - Analyze to provide additional details with [86-categories taxonomy](../Category-Taxonomy.md)
39+
- **Option 1**: Scoped Analysis - Analyze only a specified model
40+
- **Option 2**: Enhanced Analysis - Analyze to provide additional details by using [86-categories taxonomy](../Category-Taxonomy.md)
4141

4242
## Authorize the API call
4343

44-
Every call to the Computer Vision API requires a subscription key. This key needs to be either passed through a query string parameter or specified in the request header.
44+
Every call to the Computer Vision API requires a subscription key. This key must be either passed through a query string parameter or specified in the request header.
4545

46-
You can get a free trial key from [Try Cognitive Services](https://azure.microsoft.com/try/cognitive-services/?api=computer-vision). Or, follow the instructions in [Create a Cognitive Services account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account) to subscribe to Computer Vision and get your key.
46+
To get a free trial key, do either of the following:
47+
* Go to the [Try Cognitive Services](https://azure.microsoft.com/try/cognitive-services/?api=computer-vision) page.
48+
* Go to the [Create a Cognitive Services account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account) page to subscribe to Computer Vision.
4749

48-
1. Passing the subscription key through a query string, see below as a Computer Vision API example:
50+
You can pass the subscription key by doing any of the following:
4951

50-
```https://westus.api.cognitive.microsoft.com/vision/v2.0/analyze?visualFeatures=Description,Tags&subscription-key=<Your subscription key>```
52+
* Pass it through a query string, as in this Computer Vision API example:
5153

52-
1. Passing the subscription key can also be specified in the HTTP request header:
54+
```
55+
https://westus.api.cognitive.microsoft.com/vision/v2.0/analyze?visualFeatures=Description,Tags&subscription-key=<Your subscription key>
56+
```
5357

54-
```ocp-apim-subscription-key: <Your subscription key>```
58+
* Specify it in the HTTP request header:
5559

56-
1. When using the client library, the subscription key is passed in through the constructor of ComputerVisionClient, and the region is specified in a property of the client:
60+
```
61+
ocp-apim-subscription-key: <Your subscription key>
62+
```
63+
64+
* When you use the client library, pass the key through the constructor of ComputerVisionClient, and specify the region in a property of the client:
5765

5866
```
5967
var visionClient = new ComputerVisionClient(new ApiKeyServiceClientCredentials("Your subscriptionKey"))
@@ -62,13 +70,13 @@ You can get a free trial key from [Try Cognitive Services](https://azure.microso
6270
}
6371
```
6472
65-
## Upload an image to the Computer Vision API service and get back tags, descriptions and celebrities
73+
## Upload an image to the Computer Vision API service
6674
67-
The basic way to perform the Computer Vision API call is by uploading an image directly. This is done by sending a "POST" request with application/octet-stream content type together with the data read from the image. For "Tags" and "Description", this upload method will be the same for all the Computer Vision API calls. The only difference will be the query parameters the user specifies.
75+
The basic way to perform the Computer Vision API call is by uploading an image directly to return tags, a description, and celebrities. You do this by sending a "POST" request with the binary image in the HTTP body together with the data read from the image. The upload method is the same for all Computer Vision API calls. The only difference is the query parameters that you specify.
6876
69-
Here’s how to get "Tags" and "Description" for a given image:
77+
For a specified image, get tags and a description by using either of the following options:
7078
71-
**Option One:** Get list of "Tags" and one "Description"
79+
### Option 1: Get a list of tags and a description
7280
7381
```
7482
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/analyze?visualFeatures=Description,Tags&subscription-key=<Your subscription key>
@@ -88,16 +96,16 @@ using (var fs = new FileStream(@"C:\Vision\Sample.jpg", FileMode.Open))
8896
}
8997
```
9098

91-
**Option Two** Get list of "Tags" only, or list of "Description" only:
99+
### Option 2: Get a list of tags only or a description only
92100

93-
###### Tags only:
101+
For tags only, run:
94102

95103
```
96104
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/tag?subscription-key=<Your subscription key>
97105
var tagResults = await visionClient.TagImageAsync("http://contoso.com/example.jpg");
98106
```
99107

100-
###### Description only:
108+
For a description only, run:
101109

102110
```
103111
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/describe?subscription-key=<Your subscription key>
@@ -107,9 +115,9 @@ using (var fs = new FileStream(@"C:\Vision\Sample.jpg", FileMode.Open))
107115
}
108116
```
109117

110-
### Get domain-specific analysis (celebrities)
118+
## Get domain-specific analysis (celebrities)
111119

112-
**Option One:** Scoped Analysis - Analyze only a given model
120+
### Option 1: Scoped analysis - Analyze only a specified model
113121
```
114122
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/models/celebrities/analyze
115123
var celebritiesResult = await visionClient.AnalyzeImageInDomainAsync(url, "celebrities");
@@ -122,17 +130,17 @@ GET https://westus.api.cognitive.microsoft.com/vision/v2.0/models
122130
var models = await visionClient.ListModelsAsync();
123131
```
124132

125-
**Option Two:** Enhanced Analysis - Analyze to provide additional details with [86-categories taxonomy](../Category-Taxonomy.md)
133+
### Option 2: Enhanced analysis - Analyze to provide additional details by using 86-categories taxonomy
126134

127-
For applications where you want to get generic image analysis in addition to details from one or more domain-specific models, we extend the v1 API with the models query parameter.
135+
For applications where you want to get a generic image analysis in addition to details from one or more domain-specific models, extend the v1 API by using the models query parameter.
128136

129137
```
130138
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/analyze?details=celebrities
131139
```
132140

133-
When this method is invoked, we will call the 86-category classifier first. If any of the categories match that of a known/matching model, a second pass of classifier invocations will occur. For example, if "details=all", or "details" include ‘celebrities’, we will call the celebrities model after the 86-category classifier is called and the result includes the category person. This will increase latency for users interested in celebrities, compared to Option One.
141+
When you invoke this method, you first call the [86-category](../Category-Taxonomy.md) classifier. If any of the categories matches that of a known or matching model, a second pass of classifier invocations occurs. For example, if "details=all" or "details" includes "celebrities," you call the celebrities model after you call the 86-category classifier. The result includes the category person. In contrast with Option 1, this method increases latency for users who are interested in celebrities.
134142

135-
All v1 query parameters will behave the same in this case. If visualFeatures=categories is not specified, it will be implicitly enabled.
143+
In this case, all v1 query parameters behave in the same way. If you don't specify visualFeatures=categories, it's implicitly enabled.
136144

137145
## Retrieve and understand the JSON output for analysis
138146

@@ -167,19 +175,19 @@ Here's an example:
167175

168176
Field | Type | Content
169177
------|------|------|
170-
Tags | `object` | Top-level object for array of tags
171-
tags[].Name | `string` | Keyword from tags classifier
172-
tags[].Score | `number` | Confidence score, between 0 and 1.
173-
description | `object` | Top-level object for a description.
174-
description.tags[] | `string` | List of tags. If there insufficient confidence in the ability to produce a caption, the tags maybe the only information available to the caller.
178+
Tags | `object` | The top-level object for an array of tags.
179+
tags[].Name | `string` | The keyword from the tags classifier.
180+
tags[].Score | `number` | The confidence score, between 0 and 1.
181+
description | `object` | The top-level object for a description.
182+
description.tags[] | `string` | The list of tags. If there is insufficient confidence in the ability to produce a caption, the tags might be the only information available to the caller.
175183
description.captions[].text | `string` | A phrase describing the image.
176-
description.captions[].confidence | `number` | Confidence for the phrase.
184+
description.captions[].confidence | `number` | The confidence score for the phrase.
177185

178186
## Retrieve and understand the JSON output of domain-specific models
179187

180-
**Option One:** Scoped Analysis - Analyze only a given model
188+
### Option 1: Scoped analysis - Analyze only a specified model
181189

182-
The output will be an array of tags, an example will be like this example:
190+
The output is an array of tags, as shown in the following example:
183191

184192
```json
185193
{
@@ -196,9 +204,9 @@ The output will be an array of tags, an example will be like this example:
196204
}
197205
```
198206

199-
**Option Two:** Enhanced Analysis - Analyze to provide additional details with 86-categories taxonomy
207+
### Option 2: Enhanced analysis - Analyze to provide additional details by using the "86-categories" taxonomy
200208

201-
For domain-specific models using Option Two (Enhanced Analysis), the categories return type is extended. An example follows:
209+
For domain-specific models using Option 2 (enhanced analysis), the categories return type is extended, as shown in the following example:
202210

203211
```json
204212
{
@@ -225,20 +233,20 @@ For domain-specific models using Option Two (Enhanced Analysis), the categories
225233
}
226234
```
227235

228-
The categories field is a list of one or more of the [86-categories](../Category-Taxonomy.md) in the original taxonomy. Note also that categories ending in an underscore will match that category and its children (for example, people_ as well as people_group, for celebrities model).
236+
The categories field is a list of one or more of the [86 categories](../Category-Taxonomy.md) in the original taxonomy. Categories that end in an underscore match that category and its children (for example, "people_" or "people_group," for the celebrities model).
229237

230238
Field | Type | Content
231239
------|------|------|
232-
categories | `object` | Top-level object
233-
categories[].name | `string` | Name from 86-category taxonomy
234-
categories[].score | `number` | Confidence score, between 0 and 1
235-
categories[].detail | `object?` | Optional detail object
240+
categories | `object` | The top-level object.
241+
categories[].name | `string` | The name from the 86-category taxonomy list.
242+
categories[].score | `number` | The confidence score, between 0 and 1.
243+
categories[].detail | `object?` | (Optional) The detail object.
236244

237-
Note that if multiple categories match (for example, 86-category classifier returns a score for both people_ and people_young when model=celebrities), the details are attached to the most general level match (people_ in that example.)
245+
If multiple categories match (for example, the 86-category classifier returns a score for both "people_" and "people_young," when model=celebrities), the details are attached to the most general level match ("people_," in that example).
238246

239-
## Errors Responses
247+
## Error responses
240248

241-
These are identical to vision.analyze, with the additional error of NotSupportedModel error (HTTP 400), which may be returned in both Option One and Option Two scenarios. For Option Two (Enhanced Analysis), if any of the models specified in details are not recognized, the API will return a NotSupportedModel, even if one or more of them are valid. Users can call listModels to find out what models are supported.
249+
These errors are identical to those in vision.analyze, with the additional NotSupportedModel error (HTTP 400), which might be returned in both the Option 1 and Option 2 scenarios. For Option 2 (enhanced analysis), if any of the models that are specified in the details isn't recognized, the API returns a NotSupportedModel, even if one or more of them are valid. To find out what models are supported, you can call listModels.
242250

243251
## Next steps
244252

0 commit comments

Comments
 (0)