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
This article demonstrates how to call the Image Analysis API by using the REST API. The samples are written both in C# by using the Image Analysis API client library and as HTTP POST or GET calls. The article focuses on:
19
+
This article demonstrates how to call the Image Analysis API to return information about an image's visual features.
20
20
21
-
- Getting tags, a description, and categories
22
-
- Getting domain-specific information, or "celebrities"
23
-
24
-
The examples in this article demonstrate the following features:
25
-
26
-
* Analyzing an image to return an array of tags and a description
27
-
* Analyzing an image with a domain-specific model (specifically, the "celebrities" model) to return the corresponding result in JSON
28
-
29
-
The features offer the following options:
30
-
31
-
-**Option 1**: Scoped Analysis - Analyze only a specified model
32
-
-**Option 2**: Enhanced Analysis - Analyze to provide additional details by using [86-categories taxonomy](../Category-Taxonomy.md)
33
-
34
-
## Prerequisites
35
-
36
-
* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services/)
37
-
* Once you have your Azure subscription, <ahref="https://portal.azure.com/#create/Microsoft.CognitiveServicesComputerVision"title="Create a Computer Vision resource"target="_blank">create a Computer Vision resource </a> in the Azure portal to get your key and endpoint. After it deploys, click **Go to resource**.
38
-
* You will need the key and endpoint from the resource you create to connect your application to the Computer Vision service. You'll paste your key and endpoint into the code below later in the quickstart.
39
-
* You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production.
40
-
* An image URL or a path to a locally stored image
41
-
* Supported input methods: a raw image binary in the form of an application/octet-stream, or an image URL
42
-
* Supported image file formats: JPEG, PNG, GIF, and BMP
43
-
* Image file size: 4 MB or less
44
-
* Image dimensions: 50 × 50 pixels or greater
21
+
This guide assumes you have already <ahref="https://portal.azure.com/#create/Microsoft.CognitiveServicesComputerVision"title="created a Computer Vision resource"target="_blank">create a Computer Vision resource </a> and obtained a subscription key and endpoint URL. If you haven't, follow a [quickstart](../quickstarts-sdk/image-analysis-client-library.md) to get started.
45
22
46
-
## Authorize the API call
47
-
48
-
Every call to the Image Analysis API requires a subscription key. This key must be either passed through a query string parameter or specified in the request header.
49
-
50
-
You can pass the subscription key by doing any of the following:
51
-
52
-
* Pass it through a query string, as in this example:
The basic way to perform the Image Analysis 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 Image Analysis API calls. The only difference is the query parameters that you specify.
23
+
## Submit data to the service
76
24
77
-
For a specified image, get tags and a description by using either of the following options:
25
+
You submit either a local image or a remote image to the Analyze API. For local, you put the binary image data in the HTTP request body. For remote, you specify the image's URL by formatting the request body like the following: `{"url":"http://example.com/images/test.jpg"}`.
78
26
79
-
### Option 1: Get a list of tags and a description
27
+
##Determine how to process the data
80
28
81
-
```
82
-
POST https://westus.api.cognitive.microsoft.com/vision/v2.1/analyze?visualFeatures=Description,Tags&subscription-key=<Yoursubscriptionkey>
83
-
```
84
-
85
-
```csharp
86
-
using System.IO;
87
-
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
88
-
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
29
+
### Select visual features
89
30
90
-
ImageAnalysis imageAnalysis;
91
-
var features = new VisualFeatureTypes[] { VisualFeatureTypes.Tags, VisualFeatureTypes.Description };
31
+
The [Analyze API](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/56f91f2e778daf14a499f21b) gives you access to all of the service's image analysis features. You need to specify which features you want to use by setting the URL query parameters. A parameter can have multiple values, separated by commas. Each feature you specify will require additional computation time, so only specify what you need.
92
32
93
-
using (var fs = new FileStream(@"C:\Vision\Sample.jpg", FileMode.Open))
|`visualFeatures`|`Adult`| detects if the image is pornographic in nature (depicts nudity or a sex act), or is gory (depicts extreme violence or blood). Sexually suggestive content (aka racy content) is also detected.|
36
+
||`Brands`| detects various brands within an image, including the approximate location. The Brands argument is only available in English.|
37
+
||`Categories`| categorizes image content according to a taxonomy defined in documentation. This is the default value of `visualFeatures`.|
38
+
||`Color`| determines the accent color, dominant color, and whether an image is black&white.|
39
+
||`Description`| describes the image content with a complete sentence in supported languages.|
40
+
||`Faces`| detects if faces are present. If present, generate coordinates, gender and age.|
41
+
||`ImageType`| detects if image is clip art or a line drawing.|
42
+
||`Objects`| detects various objects within an image, including the approximate location. The Objects argument is only available in English.|
43
+
||`Tags`| tags the image with a detailed list of words related to the image content.|
44
+
|`details`|`Celebrities`| identifies celebrities if detected in the image.|
45
+
||`Landmarks`|identifies landmarks if detected in the image.|
98
46
99
-
### Option 2: Get a list of tags only or a description only
100
-
101
-
For tags only, run:
102
-
103
-
```
104
-
POST https://westus.api.cognitive.microsoft.com/vision/v2.1/tag?subscription-key=<Your subscription key>
105
-
var tagResults = await visionClient.TagImageAsync("http://contoso.com/example.jpg");
106
-
```
107
-
108
-
For a description only, run:
109
-
110
-
```
111
-
POST https://westus.api.cognitive.microsoft.com/vision/v2.1/describe?subscription-key=<Your subscription key>
112
-
using (var fs = new FileStream(@"C:\Vision\Sample.jpg", FileMode.Open))
GET https://westus.api.cognitive.microsoft.com/vision/v2.1/models
130
-
var models = await visionClient.ListModelsAsync();
131
-
```
51
+
### Specify languages
132
52
133
-
### Option 2: Enhanced analysis - Analyze to provide additional details by using 86-categories taxonomy
53
+
You can also specify the language of the returned data. The following URL query parameter specifies the language. The default value is `en`.
134
54
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.
55
+
|URL parameter | Value | Description|
56
+
|---|---|--|
57
+
|`language`|`en`| English|
58
+
||`es`| Spanish|
59
+
||`ja`| Japanese|
60
+
||`pt`| Portuguese|
61
+
||`zh`| Simplified Chinese|
136
62
137
-
```
138
-
POST https://westus.api.cognitive.microsoft.com/vision/v2.1/analyze?details=celebrities
139
-
```
63
+
A populated URL might look like the following:
140
64
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.
In this case, all v1 query parameters behave in the same way. If you don't specify visualFeatures=categories, it's implicitly enabled.
67
+
> [!NOTE]
68
+
> **Scoped API calls**
69
+
>
70
+
> Some of the features in Image Analysis can be called directly as well as through the Analyze API call. For example, you can do a scoped analysis of only image tags by making a request to `https://{endpoint}/vision/v3.2-preview.3/tag`. See the [reference documentation](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/56f91f2e778daf14a499f21b) for other features that can be called separately.
144
71
145
-
## Retrieve and understand the JSON output for analysis
72
+
## Get results from the service
146
73
147
-
Here's an example:
74
+
The service returns a `200` HTTP response, and the body contains the returned data in the form of a JSON string. The following is an example of a JSON response.
148
75
149
76
```json
150
77
{
@@ -173,81 +100,39 @@ Here's an example:
173
100
}
174
101
```
175
102
103
+
See the following table for explanations of the fields in this example:
104
+
176
105
Field | Type | Content
177
106
------|------|------|
178
107
Tags | `object` | The top-level object for an array of tags.
179
108
tags[].Name | `string` | The keyword from the tags classifier.
180
109
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.
110
+
description | `object` | The top-level object for an image description.
111
+
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.
183
112
description.captions[].text | `string` | A phrase describing the image.
184
113
description.captions[].confidence | `number` | The confidence score for the phrase.
185
114
186
-
## Retrieve and understand the JSON output of domain-specific models
187
-
188
-
### Option 1: Scoped analysis - Analyze only a specified model
189
-
190
-
The output is an array of tags, as shown in the following example:
191
-
192
-
```json
193
-
{
194
-
"result":[
195
-
{
196
-
"name":"golden retriever",
197
-
"score":0.98
198
-
},
199
-
{
200
-
"name":"Labrador retriever",
201
-
"score":0.78
202
-
}
203
-
]
204
-
}
205
-
```
206
-
207
-
### Option 2: Enhanced analysis - Analyze to provide additional details by using the "86-categories" taxonomy
208
-
209
-
For domain-specific models using Option 2 (enhanced analysis), the categories return type is extended, as shown in the following example:
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).
237
-
238
-
Field | Type | Content
239
-
------|------|------|
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.
244
-
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).
246
-
247
-
## Error responses
248
-
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.
115
+
### Error codes
116
+
117
+
See the following list of possible errors and their causes:
118
+
119
+
* 400
120
+
* InvalidImageUrl - Image URL is badly formatted or not accessible.
121
+
* InvalidImageFormat - Input data is not a valid image.
122
+
* InvalidImageSize - Input image is too large.
123
+
* NotSupportedVisualFeature - Specified feature type is not valid.
124
+
* NotSupportedImage - Unsupported image, e.g. child pornography.
* NotSupportedLanguage - The requested operation is not supported in the language specified.
127
+
* BadArgument - Additional details are provided in the error message.
128
+
* 415 - Unsupported media type error. The Content-Type is not in the allowed types:
129
+
* For an image URL: Content-Type should be application/json
130
+
* For a binary image data: Content-Type should be application/octet-stream or multipart/form-data
131
+
* 500
132
+
* FailedToProcess
133
+
* Timeout - Image processing timed out.
134
+
* InternalServerError
250
135
251
136
## Next steps
252
137
253
-
To use the REST API, go to the [Image Analysis API Reference](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/56f91f2e778daf14a499f21b).
138
+
To try out the REST API, go to the [Image Analysis API Reference](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/56f91f2e778daf14a499f21b).
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/Vision-API-How-to-Topics/call-read-api.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,8 @@ ms.author: pafarley
17
17
18
18
In this guide, you'll learn how to call the Read API to extract text from images. You'll learn the different ways you can configure the behavior of this API to meet your needs.
19
19
20
+
This guide assumes you have already <ahref="https://portal.azure.com/#create/Microsoft.CognitiveServicesComputerVision"title="created a Computer Vision resource"target="_blank">create a Computer Vision resource </a> and obtained a subscription key and endpoint URL. If you haven't, follow a [quickstart](../quickstarts-sdk/client-library.md) to get started.
21
+
20
22
## Submit data to the service
21
23
22
24
The Read API's [Read call](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/5d986960601faab4bf452005) takes an image or PDF document as the input and extracts text asynchronously.
@@ -139,4 +141,4 @@ The [Read 3.2 preview API](https://westus.dev.cognitive.microsoft.com/docs/servi
139
141
140
142
## Next steps
141
143
142
-
To use the REST API, go to the [Read API Reference](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/5d986960601faab4bf452005).
144
+
To try out the REST API, go to the [Read API Reference](https://westus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2-preview-3/operations/5d986960601faab4bf452005).
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/includes/quickstarts-sdk/csharp-sdk.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,8 +178,10 @@ If you want to clean up and remove a Cognitive Services subscription, you can de
178
178
179
179
## Next steps
180
180
181
+
In this quickstart, you learned how to install the OCR client library and use the Read API. Next, learn more about the Read API features.
182
+
181
183
> [!div class="nextstepaction"]
182
-
>[Computer Vision API reference (.NET)](/dotnet/api/overview/azure/cognitiveservices/client/computervision)
184
+
>[Call the Read API](../../Vision-API-How-to-Topics/call-read-api.md)
183
185
184
186
*[OCR overview](../../overview-ocr.md)
185
187
* The source code for this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/dotnet/ComputerVision/ComputerVisionQuickstart.cs).
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/includes/quickstarts-sdk/go-sdk.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,9 +177,10 @@ If you want to clean up and remove a Cognitive Services subscription, you can de
177
177
178
178
## Next steps
179
179
180
-
> [!div class="nextstepaction"]
181
-
> [OCR API reference (Go)](https://godoc.org/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.1/computervision)
180
+
In this quickstart, you learned how to install the OCR client library and use the Read API. Next, learn more about the Read API features.
182
181
182
+
> [!div class="nextstepaction"]
183
+
>[Call the Read API](../../Vision-API-How-to-Topics/call-read-api.md)
183
184
184
185
*[OCR overview](../../overview-ocr.md)
185
186
* The source code for this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/go/ComputerVision/ComputerVisionQuickstart.go).
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/includes/quickstarts-sdk/image-analysis-csharp-sdk.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -255,8 +255,11 @@ If you want to clean up and remove a Cognitive Services subscription, you can de
255
255
256
256
## Next steps
257
257
258
+
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.
259
+
260
+
258
261
> [!div class="nextstepaction"]
259
-
>[Image Analysis API reference (.NET)](/dotnet/api/overview/azure/cognitiveservices/client/computervision)
262
+
>[Call the Analyze API](../../Vision-API-How-to-Topics/HowToCallVisionAPI.md)
* The source code for this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/dotnet/ComputerVision/ComputerVisionQuickstart.cs).
Copy file name to clipboardExpand all lines: articles/cognitive-services/Computer-vision/includes/quickstarts-sdk/image-analysis-go-sdk.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -229,9 +229,11 @@ If you want to clean up and remove a Cognitive Services subscription, you can de
229
229
230
230
## Next steps
231
231
232
-
> [!div class="nextstepaction"]
233
-
> [Image Analysis API reference (Go)](https://godoc.org/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.1/computervision)
232
+
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.
234
233
234
+
> [!div class="nextstepaction"]
235
+
>[Call the Analyze API](../../Vision-API-How-to-Topics/HowToCallVisionAPI.md)
* The source code for this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/go/ComputerVision/ComputerVisionQuickstart.go).
0 commit comments