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
# Azure AI Vision Image Analysis client library for JavaScript
1
+
# Azure ImageAnalysis REST client library for JavaScript
2
2
3
-
The Image Analysis service provides AI algorithms for processing images and returning information about their content. In a single service call, you can extract one or more visual features from the image simultaneously, including getting a caption for the image, extracting text shown in the image (OCR) and detecting objects. For more information on the service and the supported visual features, see [Image Analysis overview][image_analysis_overview], and the [Concepts][image_analysis_concepts] page.
4
3
5
-
Use the Image Analysis client library to:
6
-
* Authenticate against the service
7
-
* Set what features you would like to extract
8
-
* Upload an image for analysis, or send an image URL
**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
-[LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
23
-
- Latest versions of Safari, Chrome, Edge, and Firefox.
24
-
25
-
See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
16
+
- LTS versions of Node.js
26
17
27
18
### Prerequisites
28
19
29
-
- An [Azure subscription](https://azure.microsoft.com/free).
30
-
- A [Computer Vision resource](https://portal.azure.com/#create/Microsoft.CognitiveServicesComputerVision) in your Azure subscription.
31
-
* You will need the key and endpoint from this resource to authenticate against the service.
32
-
* You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production.
33
-
* Note that in order to run Image Analysis with the `Caption` or `Dense Captions` features, the Azure resource needs to be from one of the following GPU-supported regions: `East US`, `France Central`, `Korea Central`, `North Europe`, `Southeast Asia`, `West Europe`, or `West US`.
20
+
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
34
21
35
22
### Install the `@azure-rest/ai-vision-image-analysis` package
36
23
37
-
Install the Image Analysis client library for JavaScript with `npm`:
24
+
Install the Azure ImageAnalysis REST client REST client library for JavaScript with `npm`:
38
25
39
26
```bash
40
27
npm install @azure-rest/ai-vision-image-analysis
41
28
```
42
29
43
-
### Browser support
44
-
45
-
#### JavaScript Bundle
46
-
47
-
To use this client library in the browser, first, you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).
48
-
49
-
## Key concepts
50
-
51
-
Once you've initialized an `ImageAnalysisClient`, you need to select one or more visual features to analyze. The options are specified by the enum class `VisualFeatures`. The following features are supported:
52
-
53
-
1.`VisualFeatures.Caption`: ([Examples](#analyze-an-image-from-url) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/vision/ai-vision-image-analysis-rest/samples)) Generate a human-readable sentence that describes the content of an image.
54
-
1.`VisualFeatures.Read`: ([Examples](#extract-text-from-an-image-url) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/vision/ai-vision-image-analysis-rest/samples)) Also known as Optical Character Recognition (OCR). Extract printed or handwritten text from images.
55
-
1.`VisualFeatures.DenseCaptions`: Dense Captions provides more details by generating one-sentence captions for up to 10 different regions in the image, including one for the whole image.
56
-
1.`VisualFeatures.Tags`: Extract content tags for thousands of recognizable objects, living beings, scenery, and actions that appear in images.
57
-
1.`VisualFeatures.Objects`: Object detection. This is similar to tagging, but focused on detecting physical objects in the image and returning their location.
58
-
1.`VisualFeatures.SmartCrops`: Used to find a representative sub-region of the image for thumbnail generation, with priority given to include faces.
59
-
1.`VisualFeatures.People`: Locate people in the image and return their location.
60
-
61
-
For more information about these features, see [Image Analysis overview][image_analysis_overview], and the [Concepts][image_analysis_concepts] page.
62
-
63
-
### Supported image formats
64
-
65
-
Image Analysis works on images that meet the following requirements:
66
-
67
-
* The image must be presented in JPEG, PNG, GIF, BMP, WEBP, ICO, TIFF, or MPO format
68
-
* The file size of the image must be less than 20 megabytes (MB)
69
-
* The dimensions of the image must be greater than 50 x 50 pixels and less than 16,000 x 16,000 pixels
30
+
### Create and authenticate a `ImageAnalysisClient`
70
31
71
-
### ImageAnalysisClient
32
+
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
33
+
provide an instance of the desired credential type obtained from the
The `ImageAnalysisClient` is the primary interface for developers interacting with the Image Analysis service. It serves as the gateway from which all interaction with the library will occur.
36
+
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
74
37
75
-
## Examples
38
+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
39
+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
40
+
can be used to authenticate the client.
76
41
77
-
### Authenticate the client
78
-
79
-
Here's an example of how to create an `ImageAnalysisClient` instance using a key-based authentication.
#### Create ImageAnalysisClient with a Microsoft Entra ID Credential
99
-
100
-
Client subscription key authentication is used in most of the examples in this getting started guide, but you can also authenticate with Microsoft Entra ID (formerly Azure Active Directory) using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][azure_identity_dac] provider shown below,
101
-
or other credential providers provided with the Azure SDK, please install the Azure.Identity package:
This example demonstrates how to extract printed or hand-written text for the image file [sample.jpg](https://aka.ms/azsdk/image-analysis/sample.jpg) using the ImageAnalysisClient. The method call returns an ImageAnalysisResult object. The ReadResult property on the returned object includes a list of text lines and a bounding polygon surrounding each text line. For each line, it also returns a list of words in the text line and a bounding polygon surrounding each word.
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
208
-
209
-
## Next steps
210
-
211
-
Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/vision/ai-vision-image-analysis-rest/samples) directory for detailed examples that demonstrate how to use the client libraries.
212
-
213
-
## Contributing
214
-
215
-
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
216
-
217
-
## Related projects
218
-
219
-
- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)
0 commit comments