@azure-rest/ai-vision-face 1.0.0-alpha.20240527.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +464 -0
- package/dist/browser/clientDefinitions.d.ts +962 -0
- package/dist/browser/clientDefinitions.d.ts.map +1 -0
- package/dist/browser/clientDefinitions.js +4 -0
- package/dist/browser/clientDefinitions.js.map +1 -0
- package/dist/browser/faceClient.d.ts +16 -0
- package/dist/browser/faceClient.d.ts.map +1 -0
- package/dist/browser/faceClient.js +47 -0
- package/dist/browser/faceClient.js.map +1 -0
- package/dist/browser/index.d.ts +11 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +13 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/isUnexpected.d.ts +103 -0
- package/dist/browser/isUnexpected.d.ts.map +1 -0
- package/dist/browser/isUnexpected.js +162 -0
- package/dist/browser/isUnexpected.js.map +1 -0
- package/dist/browser/logger.d.ts +2 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/dist/browser/logger.js +5 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/models.d.ts +39 -0
- package/dist/browser/models.d.ts.map +1 -0
- package/dist/browser/models.js +4 -0
- package/dist/browser/models.js.map +1 -0
- package/dist/browser/outputModels.d.ts +608 -0
- package/dist/browser/outputModels.d.ts.map +1 -0
- package/dist/browser/outputModels.js +4 -0
- package/dist/browser/outputModels.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/parameters.d.ts +761 -0
- package/dist/browser/parameters.d.ts.map +1 -0
- package/dist/browser/parameters.js +4 -0
- package/dist/browser/parameters.js.map +1 -0
- package/dist/browser/pollingHelper.d.ts +85 -0
- package/dist/browser/pollingHelper.d.ts.map +1 -0
- package/dist/browser/pollingHelper.js +97 -0
- package/dist/browser/pollingHelper.js.map +1 -0
- package/dist/browser/responses.d.ts +1475 -0
- package/dist/browser/responses.d.ts.map +1 -0
- package/dist/browser/responses.js +4 -0
- package/dist/browser/responses.js.map +1 -0
- package/dist/commonjs/clientDefinitions.d.ts +962 -0
- package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
- package/dist/commonjs/clientDefinitions.js +5 -0
- package/dist/commonjs/clientDefinitions.js.map +1 -0
- package/dist/commonjs/faceClient.d.ts +16 -0
- package/dist/commonjs/faceClient.d.ts.map +1 -0
- package/dist/commonjs/faceClient.js +50 -0
- package/dist/commonjs/faceClient.js.map +1 -0
- package/dist/commonjs/index.d.ts +11 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +16 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/isUnexpected.d.ts +103 -0
- package/dist/commonjs/isUnexpected.d.ts.map +1 -0
- package/dist/commonjs/isUnexpected.js +166 -0
- package/dist/commonjs/isUnexpected.js.map +1 -0
- package/dist/commonjs/logger.d.ts +2 -0
- package/dist/commonjs/logger.d.ts.map +1 -0
- package/dist/commonjs/logger.js +8 -0
- package/dist/commonjs/logger.js.map +1 -0
- package/dist/commonjs/models.d.ts +39 -0
- package/dist/commonjs/models.d.ts.map +1 -0
- package/dist/commonjs/models.js +5 -0
- package/dist/commonjs/models.js.map +1 -0
- package/dist/commonjs/outputModels.d.ts +608 -0
- package/dist/commonjs/outputModels.d.ts.map +1 -0
- package/dist/commonjs/outputModels.js +5 -0
- package/dist/commonjs/outputModels.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/parameters.d.ts +761 -0
- package/dist/commonjs/parameters.d.ts.map +1 -0
- package/dist/commonjs/parameters.js +5 -0
- package/dist/commonjs/parameters.js.map +1 -0
- package/dist/commonjs/pollingHelper.d.ts +85 -0
- package/dist/commonjs/pollingHelper.d.ts.map +1 -0
- package/dist/commonjs/pollingHelper.js +101 -0
- package/dist/commonjs/pollingHelper.js.map +1 -0
- package/dist/commonjs/responses.d.ts +1475 -0
- package/dist/commonjs/responses.d.ts.map +1 -0
- package/dist/commonjs/responses.js +5 -0
- package/dist/commonjs/responses.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/esm/clientDefinitions.d.ts +962 -0
- package/dist/esm/clientDefinitions.d.ts.map +1 -0
- package/dist/esm/clientDefinitions.js +4 -0
- package/dist/esm/clientDefinitions.js.map +1 -0
- package/dist/esm/faceClient.d.ts +16 -0
- package/dist/esm/faceClient.d.ts.map +1 -0
- package/dist/esm/faceClient.js +47 -0
- package/dist/esm/faceClient.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/isUnexpected.d.ts +103 -0
- package/dist/esm/isUnexpected.d.ts.map +1 -0
- package/dist/esm/isUnexpected.js +162 -0
- package/dist/esm/isUnexpected.js.map +1 -0
- package/dist/esm/logger.d.ts +2 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +5 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/models.d.ts +39 -0
- package/dist/esm/models.d.ts.map +1 -0
- package/dist/esm/models.js +4 -0
- package/dist/esm/models.js.map +1 -0
- package/dist/esm/outputModels.d.ts +608 -0
- package/dist/esm/outputModels.d.ts.map +1 -0
- package/dist/esm/outputModels.js +4 -0
- package/dist/esm/outputModels.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parameters.d.ts +761 -0
- package/dist/esm/parameters.d.ts.map +1 -0
- package/dist/esm/parameters.js +4 -0
- package/dist/esm/parameters.js.map +1 -0
- package/dist/esm/pollingHelper.d.ts +85 -0
- package/dist/esm/pollingHelper.d.ts.map +1 -0
- package/dist/esm/pollingHelper.js +97 -0
- package/dist/esm/pollingHelper.js.map +1 -0
- package/dist/esm/responses.d.ts +1475 -0
- package/dist/esm/responses.d.ts.map +1 -0
- package/dist/esm/responses.js +4 -0
- package/dist/esm/responses.js.map +1 -0
- package/dist/react-native/clientDefinitions.d.ts +962 -0
- package/dist/react-native/clientDefinitions.d.ts.map +1 -0
- package/dist/react-native/clientDefinitions.js +4 -0
- package/dist/react-native/clientDefinitions.js.map +1 -0
- package/dist/react-native/faceClient.d.ts +16 -0
- package/dist/react-native/faceClient.d.ts.map +1 -0
- package/dist/react-native/faceClient.js +47 -0
- package/dist/react-native/faceClient.js.map +1 -0
- package/dist/react-native/index.d.ts +11 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +13 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/isUnexpected.d.ts +103 -0
- package/dist/react-native/isUnexpected.d.ts.map +1 -0
- package/dist/react-native/isUnexpected.js +162 -0
- package/dist/react-native/isUnexpected.js.map +1 -0
- package/dist/react-native/logger.d.ts +2 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +5 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/models.d.ts +39 -0
- package/dist/react-native/models.d.ts.map +1 -0
- package/dist/react-native/models.js +4 -0
- package/dist/react-native/models.js.map +1 -0
- package/dist/react-native/outputModels.d.ts +608 -0
- package/dist/react-native/outputModels.d.ts.map +1 -0
- package/dist/react-native/outputModels.js +4 -0
- package/dist/react-native/outputModels.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/parameters.d.ts +761 -0
- package/dist/react-native/parameters.d.ts.map +1 -0
- package/dist/react-native/parameters.js +4 -0
- package/dist/react-native/parameters.js.map +1 -0
- package/dist/react-native/pollingHelper.d.ts +85 -0
- package/dist/react-native/pollingHelper.d.ts.map +1 -0
- package/dist/react-native/pollingHelper.js +97 -0
- package/dist/react-native/pollingHelper.js.map +1 -0
- package/dist/react-native/responses.d.ts +1475 -0
- package/dist/react-native/responses.d.ts.map +1 -0
- package/dist/react-native/responses.js +4 -0
- package/dist/react-native/responses.js.map +1 -0
- package/package.json +157 -0
- package/review/ai-vision-face.api.md +4815 -0
package/README.md
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
# Azure AI Face client library for JavaScript
|
|
2
|
+
|
|
3
|
+
The Azure AI Face service provides AI algorithms that detect, recognize, and analyze human faces in images. It includes the following main features:
|
|
4
|
+
|
|
5
|
+
- Face detection and analysis
|
|
6
|
+
- Liveness detection
|
|
7
|
+
- Face recognition
|
|
8
|
+
- Face verification ("one-to-one" matching)
|
|
9
|
+
- Face identification ("one-to-many" matching)
|
|
10
|
+
- Find similar faces
|
|
11
|
+
- Group faces
|
|
12
|
+
|
|
13
|
+
[Product documentation](https://learn.microsoft.com/azure/ai-services/computer-vision/overview-identity)
|
|
14
|
+
| [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/face/ai-vision-face-rest)
|
|
15
|
+
| [Package (NPM)](https://www.npmjs.com/package/@azure-rest/ai-vision-face)
|
|
16
|
+
| [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/face/ai-vision-face-rest/samples)
|
|
17
|
+
| [API reference documentation](https://aka.ms/azsdk-javascript-face-ref)
|
|
18
|
+
|
|
19
|
+
## Getting started
|
|
20
|
+
|
|
21
|
+
### Currently supported environments
|
|
22
|
+
|
|
23
|
+
- LTS versions of Node.js
|
|
24
|
+
|
|
25
|
+
See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
|
|
26
|
+
|
|
27
|
+
### Prerequisites
|
|
28
|
+
|
|
29
|
+
- An [Azure subscription](https://azure.microsoft.com/free/).
|
|
30
|
+
- Your Azure account must have a `Cognitive Services Contributor` role assigned in order for you to agree to the responsible AI terms and create a resource. To get this role assigned to your account, follow the steps in the [Assign roles](https://learn.microsoft.com/azure/role-based-access-control/role-assignments-steps) documentation, or contact your administrator.
|
|
31
|
+
- Once you have sufficient permissions to control your Azure subscription, you need either
|
|
32
|
+
- an [Azure Face account](https://portal.azure.com/#blade/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/Face) or
|
|
33
|
+
- an [Azure AI services multi-service account](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/AllInOne)
|
|
34
|
+
|
|
35
|
+
### Create a Face or an Azure AI services multi-service account
|
|
36
|
+
|
|
37
|
+
Azure AI Face supports both [multi-service](https://learn.microsoft.com/azure/ai-services/multi-service-resource?tabs=windows&pivots=azportal#supported-services-with-a-multi-service-resource) and single-service access. Create an Azure AI services multi-service account if you plan to access multiple Azure AI services under a single endpoint/key. For Face access only, create a Face resource.
|
|
38
|
+
|
|
39
|
+
- To create a new Face or Azure AI services multi-service account, you can use [Azure Portal](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesFace), [Azure PowerShell](https://learn.microsoft.com/azure/ai-services/multi-service-resource?tabs=windows&pivots=azpowershell), or [Azure CLI](https://learn.microsoft.com/azure/ai-services/multi-service-resource?tabs=windows&pivots=azcli).
|
|
40
|
+
|
|
41
|
+
### Install the package
|
|
42
|
+
|
|
43
|
+
Install the Azure Face REST client library for JavaScript with `npm`:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install @azure-rest/ai-vision-face
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Authenticate the client
|
|
50
|
+
|
|
51
|
+
In order to interact with the Face service, you will need to create an instance of a client.
|
|
52
|
+
An **endpoint** and **credential** are necessary to instantiate the client object.
|
|
53
|
+
|
|
54
|
+
Both key credential and Microsoft Entra ID credential are supported to authenticate the client.
|
|
55
|
+
For enhanced security, we strongly recommend utilizing Microsoft Entra ID credential for authentication in the production environment, while AzureKeyCredential should be reserved exclusively for the testing environment.
|
|
56
|
+
|
|
57
|
+
#### Get the endpoint
|
|
58
|
+
|
|
59
|
+
You can find the endpoint for your Face resource using the Azure Portal or Azure CLI:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Get the endpoint for the Face resource
|
|
63
|
+
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Either a regional endpoint or a custom subdomain can be used for authentication. They are formatted as follows:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
Regional endpoint: https://<region>.api.cognitive.microsoft.com/
|
|
70
|
+
Custom subdomain: https://<resource-name>.cognitiveservices.azure.com/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
A regional endpoint is the same for every resource in a region. A complete list of supported regional endpoints can be consulted [here](https://azure.microsoft.com/global-infrastructure/services/?products=cognitive-services). Please note that regional endpoints do not support Microsoft Entra ID authentication. If you'd like migrate your resource to use custom subdomain, follow the instructions [here](https://learn.microsoft.com/azure/ai-services/cognitive-services-custom-subdomains#how-does-this-impact-existing-resources).
|
|
74
|
+
|
|
75
|
+
A custom subdomain, on the other hand, is a name that is unique to the resource. Once created and linked to a resource, it cannot be modified.
|
|
76
|
+
|
|
77
|
+
#### Create the client with a Microsoft Entra ID credential
|
|
78
|
+
|
|
79
|
+
`AzureKeyCredential` authentication is used in the examples in this getting started guide, but you can also authenticate with Microsoft Entra ID using the [@azure/identity](https://learn.microsoft.com/javascript/api/@azure/identity/?view=azure-node-latest) library.
|
|
80
|
+
Note that regional endpoints do not support Microsoft Entra ID authentication. Create a [custom subdomain](https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain) name for your resource in order to use this type of authentication.
|
|
81
|
+
|
|
82
|
+
To use the [DefaultAzureCredential](https://learn.microsoft.com/javascript/api/@azure/identity/defaultazurecredential?view=azure-node-latest) type shown below, or other credential types provided with the Azure SDK, please install the `@azure/identity` package:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
npm install --save @azure/identity
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You will also need to [register a new Microsoft Entra ID application and grant access](https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal) to Face by assigning the `"Cognitive Services User"` role to your service principal.
|
|
89
|
+
|
|
90
|
+
Once completed, set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables:
|
|
91
|
+
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
/**
|
|
95
|
+
* DefaultAzureCredential will use the values from these environment
|
|
96
|
+
* variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
97
|
+
*/
|
|
98
|
+
import { DefaultAzureCredential } from '@azure/identity';
|
|
99
|
+
import createFaceClient from '@azure-rest/ai-vision-face';
|
|
100
|
+
|
|
101
|
+
const endpoint = process.env['FACE_ENDPOINT'] || '<endpoint>';
|
|
102
|
+
const credential = new DefaultAzureCredential();
|
|
103
|
+
const client = createFaceClient(endpoint, credential);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Create the client with AzureKeyCredential
|
|
107
|
+
|
|
108
|
+
To use an API key as the `credential` parameter, pass the key as a string into an instance of [AzureKeyCredential](https://learn.microsoft.com/javascript/api/@azure/core-auth/azurekeycredential?view=azure-node-latest).
|
|
109
|
+
You can get the API key for your Face resource using the [Azure Portal](https://learn.microsoft.com/azure/ai-services/multi-service-resource?tabs=windows&pivots=azportal#get-the-keys-for-your-resource) or [Azure CLI](https://learn.microsoft.com/azure/ai-services/multi-service-resource?tabs=windows&pivots=azcli#get-the-keys-for-your-resource):
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Get the API keys for the Face resource
|
|
113
|
+
az cognitiveservices account keys list --name "<resource-name>" --resource-group "<resource-group-name>"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import { AzureKeyCredential } from '@azure/core-auth';
|
|
118
|
+
import createFaceClient from '@azure-rest/ai-vision-face';
|
|
119
|
+
|
|
120
|
+
const endpoint = process.env['FACE_ENDPOINT'] || '<endpoint>';
|
|
121
|
+
const apikey = process.env['FACE_APIKEY'] || '<apikey>';
|
|
122
|
+
const credential = new AzureKeyCredential(apikey);
|
|
123
|
+
const client = createFaceClient(endpoint, credential);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Key concepts
|
|
127
|
+
|
|
128
|
+
### FaceClient
|
|
129
|
+
|
|
130
|
+
The `FaceClient` is the primary interface for developers interacting with the Azure AI Face service. It follows the design of [REST client](https://devblogs.microsoft.com/azure-sdk/azure-rest-libraries-for-javascript/) and serves as the gateway from which all interaction with the library will occur.
|
|
131
|
+
|
|
132
|
+
### Long-running operations
|
|
133
|
+
|
|
134
|
+
Long-running operations are operations which consist of an initial request sent to the service to start an operation, followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has succeeded, to get the result. For more information, please refer to the "Long-running operations" section in this [blog post](https://devblogs.microsoft.com/azure-sdk/azure-rest-libraries-for-javascript/).
|
|
135
|
+
|
|
136
|
+
Current long-running face operations:
|
|
137
|
+
|
|
138
|
+
- Face list operations
|
|
139
|
+
- [Train large face list](https://learn.microsoft.com/rest/api/face/face-list-operations/train-large-face-list?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
140
|
+
- Person group operations
|
|
141
|
+
- [Train large person group](https://learn.microsoft.com/rest/api/face/person-group-operations/update-large-person-group?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
142
|
+
- [Train person group](https://learn.microsoft.com/rest/api/face/person-group-operations/train-person-group?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
143
|
+
- Person directory operations
|
|
144
|
+
- [Add person face](https://learn.microsoft.com/rest/api/face/person-directory-operations/add-person-face?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
145
|
+
- [Add person face from URL](https://learn.microsoft.com/rest/api/face/person-directory-operations/add-person-face-from-url?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
146
|
+
- [Create dynamic person group with person](https://learn.microsoft.com/rest/api/face/person-directory-operations/create-dynamic-person-group-with-person?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
147
|
+
- [Create person](https://learn.microsoft.com/rest/api/face/person-directory-operations/create-person?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
148
|
+
- [Delete dynamic person group](https://learn.microsoft.com/rest/api/face/person-directory-operations/delete-dynamic-person-group?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
149
|
+
- [Delete person](https://learn.microsoft.com/rest/api/face/person-directory-operations/delete-person?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
150
|
+
- [Delete person face](https://learn.microsoft.com/rest/api/face/person-directory-operations/delete-person-face?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
151
|
+
- [Update dynamic person group with person changes](https://learn.microsoft.com/rest/api/face/person-directory-operations/update-dynamic-person-group-with-person-changes?view=rest-face-v1.1-preview.1&tabs=HTTP)
|
|
152
|
+
|
|
153
|
+
## Examples
|
|
154
|
+
|
|
155
|
+
The following section provides several code snippets covering some of the most common Face tasks, including:
|
|
156
|
+
|
|
157
|
+
- [Detecting faces in an image](#face-detection "Face Detection")
|
|
158
|
+
- [Identifing the specific face from a LargePersonGroup](#face-recognition-from-largepersongroup "Face Recognition from LargePersonGroup")
|
|
159
|
+
- [Determining if a face in an video is real (live) or fake (spoof)](#liveness-detection "Liveness Detection")
|
|
160
|
+
|
|
161
|
+
### Face Detection
|
|
162
|
+
|
|
163
|
+
Detect faces and analyze them from an binary data.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
import { readFileSync } from 'fs';
|
|
167
|
+
import { AzureKeyCredential } from '@azure/core-auth';
|
|
168
|
+
|
|
169
|
+
import createFaceClient, {
|
|
170
|
+
isUnexpected,
|
|
171
|
+
} from '@azure-rest/ai-vision-face';
|
|
172
|
+
|
|
173
|
+
const endpoint = process.env['FACE_ENDPOINT'] || '<endpoint>';
|
|
174
|
+
const apikey = process.env['FACE_APIKEY'] || '<apikey>';
|
|
175
|
+
const credential = new AzureKeyCredential(apikey);
|
|
176
|
+
const client = createFaceClient(endpoint, credential);
|
|
177
|
+
|
|
178
|
+
const response = await client.path('/detect').post({
|
|
179
|
+
contentType: 'application/octet-stream',
|
|
180
|
+
queryParameters: {
|
|
181
|
+
detectionModel: 'detection_03',
|
|
182
|
+
recognitionModel: 'recognition_04',
|
|
183
|
+
returnFaceLandmarks: true,
|
|
184
|
+
returnRecognitionModel: true,
|
|
185
|
+
faceIdTimeToLive: 120,
|
|
186
|
+
returnFaceAttributes: ['headPose', 'mask', 'qualityForRecognition'],
|
|
187
|
+
returnFaceId: false,
|
|
188
|
+
},
|
|
189
|
+
body: readFileSync('path/to/test/image'),
|
|
190
|
+
});
|
|
191
|
+
if (isUnexpected(response)) {
|
|
192
|
+
throw new Error(response.body.error.message);
|
|
193
|
+
}
|
|
194
|
+
console.log(response.body);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Face Recognition from LargePersonGroup
|
|
198
|
+
|
|
199
|
+
Identify a face against a defined LargePersonGroup.
|
|
200
|
+
|
|
201
|
+
First, we have to create a LargePersonGroup, add a few Persons to it, and then register faces with these Persons.
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
import { readFileSync } from 'fs';
|
|
205
|
+
import { AzureKeyCredential } from '@azure/core-auth';
|
|
206
|
+
|
|
207
|
+
import createFaceClient, {
|
|
208
|
+
getLongRunningPoller,
|
|
209
|
+
isUnexpected,
|
|
210
|
+
} from '@azure-rest/ai-vision-face';
|
|
211
|
+
|
|
212
|
+
const endpoint = process.env['FACE_ENDPOINT'] || '<endpoint>';
|
|
213
|
+
const apikey = process.env['FACE_APIKEY'] || '<apikey>';
|
|
214
|
+
const credential = new AzureKeyCredential(apikey);
|
|
215
|
+
const client = createFaceClient(endpoint, credential);
|
|
216
|
+
|
|
217
|
+
const largePersonGroupId = 'lpg_family';
|
|
218
|
+
|
|
219
|
+
console.log(`Create a large person group with id: ${largePersonGroupId}`);
|
|
220
|
+
const createLargePersonGroupResponse = await client.path('/largepersongroups/{largePersonGroupId}', largePersonGroupId).put({
|
|
221
|
+
body: {
|
|
222
|
+
name: 'My Family',
|
|
223
|
+
recognitionModel: 'recognition_04',
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
console.log('Create a Person Bill and add a face to him.');
|
|
228
|
+
const createLargePersonGroupPersonResponse_bill = await client.path('/largepersongroups/{largePersonGroupId}/persons', largePersonGroupId).post({
|
|
229
|
+
body: {
|
|
230
|
+
name: 'Bill',
|
|
231
|
+
userData: 'Dad',
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
if (isUnexpected(createLargePersonGroupPersonResponse_bill)) {
|
|
235
|
+
throw new Error(createLargePersonGroupPersonResponse_bill.body.error.message);
|
|
236
|
+
}
|
|
237
|
+
const personId_bill = createLargePersonGroupPersonResponse_bill.body.personId;
|
|
238
|
+
await client.path('/largepersongroups/{largePersonGroupId}/persons/{personId}/persistedfaces', largePersonGroupId, personId_bill).post({
|
|
239
|
+
queryParameters: {
|
|
240
|
+
userData: 'Dad-0001',
|
|
241
|
+
detectionModel: 'detection_03',
|
|
242
|
+
},
|
|
243
|
+
contentType: 'application/octet-stream',
|
|
244
|
+
body: readFileSync('path/to/bill/image'),
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
console.log('Create a Person Clare and add a face to her.');
|
|
248
|
+
const createLargePersonGroupPersonResponse_clare = await client.path('/largepersongroups/{largePersonGroupId}/persons', largePersonGroupId).post({
|
|
249
|
+
body: {
|
|
250
|
+
name: 'Clare',
|
|
251
|
+
userData: 'Mom',
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
if (isUnexpected(createLargePersonGroupPersonResponse_clare)) {
|
|
255
|
+
throw new Error(createLargePersonGroupPersonResponse_clare.body.error.message);
|
|
256
|
+
}
|
|
257
|
+
const personId_clare = createLargePersonGroupPersonResponse_clare.body.personId;
|
|
258
|
+
await client.path('/largepersongroups/{largePersonGroupId}/persons/{personId}/persistedfaces', largePersonGroupId, personId_clare).post({
|
|
259
|
+
queryParameters: {
|
|
260
|
+
userData: 'Mom-0001',
|
|
261
|
+
detectionModel: 'detection_03',
|
|
262
|
+
},
|
|
263
|
+
contentType: 'application/octet-stream',
|
|
264
|
+
body: readFileSync('path/to/clare/image'),
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Before doing the identification, we must train the LargePersonGroup first.
|
|
269
|
+
|
|
270
|
+
```js
|
|
271
|
+
console.log(`Start to train the large person group: ${largePersonGroupId}`);
|
|
272
|
+
const trainResponse = await client.path('/largepersongroups/{largePersonGroupId}/train', largePersonGroupId).post();
|
|
273
|
+
const trainPoller = await getLongRunningPoller(client, trainResponse);
|
|
274
|
+
await trainPoller.pollUntilDone();
|
|
275
|
+
// Check if poller.getOperationState().status is 'succeeded'.
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
When the training operation is completed successfully, we can identify the faces in this LargePersonGroup throught.
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
console.log('Detect faces from the target image.');
|
|
282
|
+
const detectResponse = await client.path('/detect').post({
|
|
283
|
+
contentType: 'application/octet-stream',
|
|
284
|
+
queryParameters: {
|
|
285
|
+
detectionModel: 'detection_03',
|
|
286
|
+
recognitionModel: 'recognition_04',
|
|
287
|
+
returnFaceId: true,
|
|
288
|
+
},
|
|
289
|
+
body: readFileSync('path/to/target/image'),
|
|
290
|
+
});
|
|
291
|
+
if (isUnexpected(detectResponse)) {
|
|
292
|
+
throw new Error(detectResponse.body.error.message);
|
|
293
|
+
}
|
|
294
|
+
const faceIds = detectResponse.body.map(face => face.faceId as string)
|
|
295
|
+
|
|
296
|
+
console.log('Identify the faces in the large person group.');
|
|
297
|
+
const identifyResponse = await client.path('/identify').post({
|
|
298
|
+
body: { faceIds, largePersonGroupId },
|
|
299
|
+
});
|
|
300
|
+
if (isUnexpected(identifyResponse)) {
|
|
301
|
+
throw new Error(identifyResponse.body.error.message);
|
|
302
|
+
}
|
|
303
|
+
console.log(identifyResponse.body);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Finally, remove the large person group if you don't need it anymore.
|
|
307
|
+
|
|
308
|
+
```js
|
|
309
|
+
console.log(`Delete the large person group: ${largePersonGroupId}`);
|
|
310
|
+
await client.path('/largepersongroups/{largePersonGroupId}', largePersonGroupId).delete();
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Liveness detection
|
|
314
|
+
Face Liveness detection can be used to determine if a face in an input video stream is real (live) or fake (spoof).
|
|
315
|
+
The goal of liveness detection is to ensure that the system is interacting with a physically present live person at
|
|
316
|
+
the time of authentication. The whole process of authentication is called a session.
|
|
317
|
+
|
|
318
|
+
There are two different components in the authentication: a frontend application and an app server/orchestrator.
|
|
319
|
+
Before uploading the video stream, the app server has to create a session, and then the frontend client could upload
|
|
320
|
+
the payload with a `session authorization token` to call the liveness detection. The app server can query for the
|
|
321
|
+
liveness detection result and audit logs anytime until the session is deleted.
|
|
322
|
+
|
|
323
|
+
The Liveness detection operation can not only confirm if the input is live or spoof, but also verify whether the input
|
|
324
|
+
belongs to the expected person's face, which is called **liveness detection with face verification**. For the detail
|
|
325
|
+
information, please refer to the [tutorial](https://learn.microsoft.com/azure/ai-services/computer-vision/tutorials/liveness).
|
|
326
|
+
|
|
327
|
+
This package is only responsible for app server to create, query, delete a session and get audit logs. For how to
|
|
328
|
+
integrate the UI and the code into your native frontend application, please follow instructions in the [tutorial](https://learn.microsoft.com/azure/ai-services/computer-vision/tutorials/liveness).
|
|
329
|
+
|
|
330
|
+
Here is an example to create and get the liveness detection result of a session.
|
|
331
|
+
|
|
332
|
+
```js
|
|
333
|
+
import { randomUUID } from 'crypto';
|
|
334
|
+
|
|
335
|
+
import { AzureKeyCredential } from '@azure/core-auth';
|
|
336
|
+
|
|
337
|
+
import createFaceClient, {
|
|
338
|
+
isUnexpected,
|
|
339
|
+
} from '@azure-rest/ai-vision-face';
|
|
340
|
+
|
|
341
|
+
const endpoint = process.env['FACE_ENDPOINT'] || '<endpoint>';
|
|
342
|
+
const apikey = process.env['FACE_APIKEY'] || '<apikey>';
|
|
343
|
+
const credential = new AzureKeyCredential(apikey);
|
|
344
|
+
const client = createFaceClient(endpoint, credential);
|
|
345
|
+
|
|
346
|
+
console.log('Create a new liveness session.');
|
|
347
|
+
const createLivenessSessionResponse = await client.path('/detectLiveness/singleModal/sessions').post({
|
|
348
|
+
body: {
|
|
349
|
+
livenessOperationMode: 'Passive',
|
|
350
|
+
deviceCorrelationId: randomUUID(),
|
|
351
|
+
sendResultsToClient: false,
|
|
352
|
+
authTokenTimeToLiveInSeconds: 60,
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
if (isUnexpected(createLivenessSessionResponse)) {
|
|
356
|
+
throw new Error(createLivenessSessionResponse.body.error.message);
|
|
357
|
+
}
|
|
358
|
+
console.log(createLivenessSessionResponse.body);
|
|
359
|
+
|
|
360
|
+
const { sessionId } = createLivenessSessionResponse.body;
|
|
361
|
+
|
|
362
|
+
console.log('Get liveness detection results.');
|
|
363
|
+
const getLivenessSessionResponse = await client.path('/detectLiveness/singleModal/sessions/{sessionId}', sessionId).get();
|
|
364
|
+
if (isUnexpected(getLivenessSessionResponse)) {
|
|
365
|
+
throw new Error(getLivenessSessionResponse.body.error.message);
|
|
366
|
+
}
|
|
367
|
+
console.log(getLivenessSessionResponse.body);
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Here is another example for the liveness detection with face verification.
|
|
371
|
+
|
|
372
|
+
```js
|
|
373
|
+
import { randomUUID } from 'crypto';
|
|
374
|
+
import { readFileSync } from 'fs';
|
|
375
|
+
|
|
376
|
+
import { AzureKeyCredential } from '@azure/core-auth';
|
|
377
|
+
|
|
378
|
+
import createFaceClient, {
|
|
379
|
+
isUnexpected,
|
|
380
|
+
} from '@azure-rest/ai-vision-face';
|
|
381
|
+
|
|
382
|
+
const endpoint = process.env['FACE_ENDPOINT'] || '<endpoint>';
|
|
383
|
+
const apikey = process.env['FACE_APIKEY'] || '<apikey>';
|
|
384
|
+
const credential = new AzureKeyCredential(apikey);
|
|
385
|
+
const client = createFaceClient(endpoint, credential);
|
|
386
|
+
|
|
387
|
+
console.log('Create a new liveness with verify session with verify image.');
|
|
388
|
+
const createLivenessSessionResponse = await client.path('/detectLivenessWithVerify/singleModal/sessions').post({
|
|
389
|
+
contentType: 'multipart/form-data',
|
|
390
|
+
body: [
|
|
391
|
+
{
|
|
392
|
+
name: 'VerifyImage',
|
|
393
|
+
body: readFileSync('path/to/verify/image'),
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
name: 'Parameters',
|
|
397
|
+
body: {
|
|
398
|
+
livenessOperationMode: 'Passive',
|
|
399
|
+
sendResultsToClient: false,
|
|
400
|
+
authTokenTimeToLiveInSeconds: 60,
|
|
401
|
+
deviceCorrelationId: randomUUID(),
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
});
|
|
406
|
+
if (isUnexpected(createLivenessSessionResponse)) {
|
|
407
|
+
throw new Error(createLivenessSessionResponse.body.error.message);
|
|
408
|
+
}
|
|
409
|
+
console.log(createLivenessSessionResponse.body);
|
|
410
|
+
|
|
411
|
+
const { sessionId } = createLivenessSessionResponse.body;
|
|
412
|
+
|
|
413
|
+
console.log('Get the liveness detection and verification result.');
|
|
414
|
+
const getLivenessSessionResultResponse = await client.path('/detectLivenessWithVerify/singleModal/sessions/{sessionId}', sessionId).get();
|
|
415
|
+
if (isUnexpected(getLivenessSessionResultResponse)) {
|
|
416
|
+
throw new Error(getLivenessSessionResultResponse.body.error.message);
|
|
417
|
+
}
|
|
418
|
+
console.log(getLivenessSessionResultResponse.body);
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Troubleshooting
|
|
422
|
+
|
|
423
|
+
### General
|
|
424
|
+
|
|
425
|
+
Error codes and messages raised by the Face service can be found in the [service documentation](https://aka.ms/face-error-codes-and-messages).
|
|
426
|
+
|
|
427
|
+
### Logging
|
|
428
|
+
|
|
429
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
430
|
+
|
|
431
|
+
```javascript
|
|
432
|
+
const { setLogLevel } = require("@azure/logger");
|
|
433
|
+
|
|
434
|
+
setLogLevel("info");
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
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).
|
|
438
|
+
|
|
439
|
+
## Next steps
|
|
440
|
+
|
|
441
|
+
### More sample code
|
|
442
|
+
|
|
443
|
+
See the [Sample README](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/face/ai-vision-face-rest/samples) for several code snippets illustrating common patterns used in the Face JavaScript API.
|
|
444
|
+
|
|
445
|
+
### Additional documentation
|
|
446
|
+
|
|
447
|
+
For more extensive documentation on Azure AI Face, see the [Face documentation](https://learn.microsoft.com/azure/ai-services/computer-vision/overview-identity) on learn.microsoft.com.
|
|
448
|
+
|
|
449
|
+
## Contributing
|
|
450
|
+
|
|
451
|
+
This project welcomes contributions and suggestions. Most contributions require
|
|
452
|
+
you to agree to a Contributor License Agreement (CLA) declaring that you have
|
|
453
|
+
the right to, and actually do, grant us the rights to use your contribution.
|
|
454
|
+
For details, visit https://cla.microsoft.com.
|
|
455
|
+
|
|
456
|
+
When you submit a pull request, a CLA-bot will automatically determine whether
|
|
457
|
+
you need to provide a CLA and decorate the PR appropriately (e.g., label,
|
|
458
|
+
comment). Simply follow the instructions provided by the bot. You will only
|
|
459
|
+
need to do this once across all repos using our CLA.
|
|
460
|
+
|
|
461
|
+
This project has adopted the
|
|
462
|
+
[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information,
|
|
463
|
+
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
|
|
464
|
+
additional questions or comments.
|