You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/Vision-API-How-to-Topics/HowToCallVisionAPI.md
+63-55Lines changed: 63 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "Example: Call the Analyze image API - Computer Vision"
2
+
title: Call the Computer Vision API
3
3
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.
5
5
services: cognitive-services
6
6
author: KellyDF
7
7
manager: nitinme
@@ -14,46 +14,54 @@ ms.author: kefre
14
14
ms.custom: seodec18
15
15
---
16
16
17
-
# Example: How to call the Computer Vision API
17
+
# Call the Computer Vision API
18
18
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:
20
20
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"
23
23
24
24
## Prerequisites
25
25
26
-
-Image URL or path to locally stored image.
27
-
- Supported input methods: Raw image binary in the form of an application/octetstream 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
31
31
32
-
In the examples below, the following features are demonstrated:
32
+
The examples in this article demonstrate the following features:
33
33
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
36
36
37
-
Features are broken down on:
37
+
The features offer the following options:
38
38
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)
41
41
42
42
## Authorize the API call
43
43
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.
45
45
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.
47
49
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:
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:
* When you use the client library, pass the key through the constructor of ComputerVisionClient, and specify the region in a property of the client:
57
65
58
66
```
59
67
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
62
70
}
63
71
```
64
72
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
66
74
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.
68
76
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:
70
78
71
-
**Option One:** Get list of "Tags" and one "Description"
79
+
### Option 1: Get a list of tags and a description
72
80
73
81
```
74
82
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/analyze?visualFeatures=Description,Tags&subscription-key=<Yoursubscriptionkey>
@@ -88,16 +96,16 @@ using (var fs = new FileStream(@"C:\Vision\Sample.jpg", FileMode.Open))
88
96
}
89
97
```
90
98
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
92
100
93
-
###### Tags only:
101
+
For tags only, run:
94
102
95
103
```
96
104
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/tag?subscription-key=<Your subscription key>
97
105
var tagResults = await visionClient.TagImageAsync("http://contoso.com/example.jpg");
98
106
```
99
107
100
-
###### Description only:
108
+
For a description only, run:
101
109
102
110
```
103
111
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))
107
115
}
108
116
```
109
117
110
-
###Get domain-specific analysis (celebrities)
118
+
## Get domain-specific analysis (celebrities)
111
119
112
-
**Option One:** Scoped Analysis - Analyze only a given model
120
+
### Option 1: Scoped analysis - Analyze only a specified model
113
121
```
114
122
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/models/celebrities/analyze
115
123
var celebritiesResult = await visionClient.AnalyzeImageInDomainAsync(url, "celebrities");
@@ -122,17 +130,17 @@ GET https://westus.api.cognitive.microsoft.com/vision/v2.0/models
122
130
var models = await visionClient.ListModelsAsync();
123
131
```
124
132
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
126
134
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.
128
136
129
137
```
130
138
POST https://westus.api.cognitive.microsoft.com/vision/v2.0/analyze?details=celebrities
131
139
```
132
140
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.
134
142
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.
136
144
137
145
## Retrieve and understand the JSON output for analysis
138
146
@@ -167,19 +175,19 @@ Here's an example:
167
175
168
176
Field | Type | Content
169
177
------|------|------|
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.
175
183
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.
177
185
178
186
## Retrieve and understand the JSON output of domain-specific models
179
187
180
-
**Option One:** Scoped Analysis - Analyze only a given model
188
+
### Option 1: Scoped analysis - Analyze only a specified model
181
189
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:
183
191
184
192
```json
185
193
{
@@ -196,9 +204,9 @@ The output will be an array of tags, an example will be like this example:
196
204
}
197
205
```
198
206
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
200
208
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:
202
210
203
211
```json
204
212
{
@@ -225,20 +233,20 @@ For domain-specific models using Option Two (Enhanced Analysis), the categories
225
233
}
226
234
```
227
235
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 [86categories](../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).
229
237
230
238
Field | Type | Content
231
239
------|------|------|
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
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.
236
244
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).
238
246
239
-
## Errors Responses
247
+
## Error responses
240
248
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.
0 commit comments