express-sweet 1.0.19 → 1.0.20
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/CHANGELOG.md +62 -1
- package/dist/build.common.js +2 -2
- package/dist/build.esm.js +3 -3
- package/docs/index.html +260 -52
- package/package.json +2 -2
- package/types/database/Model.d.ts +1 -1
- package/types/interfaces/BoundingBox.d.ts +1 -1
- package/types/interfaces/FaceDetailsEmotions.d.ts +40 -0
- package/types/services/AWSRekognitionClient.d.ts +9 -241
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import RekognitionOptions from '~/interfaces/RekognitionOptions';
|
|
2
2
|
import FaceMatch from '~/interfaces/FaceMatch';
|
|
3
3
|
import BoundingBox from '~/interfaces/BoundingBox';
|
|
4
|
+
import FaceDetails from '~/interfaces/FaceDetails';
|
|
4
5
|
/**
|
|
5
6
|
* AWS Rekognition Client.
|
|
6
7
|
*/
|
|
7
8
|
export default class {
|
|
8
9
|
/**
|
|
9
|
-
* Rekognition
|
|
10
|
+
* Rekognition Client.
|
|
10
11
|
* @type {AWS.Rekognition}
|
|
11
12
|
*/
|
|
12
13
|
private client;
|
|
@@ -18,63 +19,18 @@ export default class {
|
|
|
18
19
|
* Detects faces within an image that is provided as input.
|
|
19
20
|
* For each face detected, the operation returns a bounding box of the face.
|
|
20
21
|
*
|
|
21
|
-
* @example
|
|
22
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
23
|
-
* const fs = require('fs');
|
|
24
|
-
*
|
|
25
|
-
* // Instantiate Rekognition client.
|
|
26
|
-
* const client = new AWSRekognitionClient({
|
|
27
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
28
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
29
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Detect faces from path.
|
|
33
|
-
* // Output: [
|
|
34
|
-
* // {
|
|
35
|
-
* // width: 0.5004957914352417,
|
|
36
|
-
* // height: 0.6926820874214172,
|
|
37
|
-
* // left: 0.2928674817085266,
|
|
38
|
-
* // top: 0.09095800668001175
|
|
39
|
-
* // }
|
|
40
|
-
* // ]
|
|
41
|
-
* await client.detectFaces('img.jpg');
|
|
42
|
-
*
|
|
43
|
-
* // Detect faces from data URL.
|
|
44
|
-
* await client.detectFaces('data:image/png;base64,/9j/4...');
|
|
45
|
-
*
|
|
46
|
-
* // Detect faces from buffer.
|
|
47
|
-
* await client.detectFaces(fs.readFileSync('img.jpg'));
|
|
48
|
-
*
|
|
49
22
|
* @param {string} img Image path or Data Url or image buffer.
|
|
50
23
|
* @param {number} minConfidence The minimum confidence of the detected face.
|
|
51
24
|
* Faces with a confidence lower than this value will not be returned as a result.
|
|
52
|
-
* @
|
|
25
|
+
* @param {boolean} withDetails If false, returns only the face bounding box.
|
|
26
|
+
* When true, returns the age group, gender, and emotion in addition to the face bounding box.
|
|
27
|
+
*
|
|
28
|
+
* @return {Promise<BoundingBox[]|FaceDetails[]>}
|
|
53
29
|
*/
|
|
54
|
-
detectFaces(img: string, minConfidence?: number): Promise<BoundingBox[]>;
|
|
30
|
+
detectFaces(img: string, minConfidence?: number, withDetails?: boolean): Promise<BoundingBox[] | FaceDetails[]>;
|
|
55
31
|
/**
|
|
56
32
|
* Compare the similarity of two faces.
|
|
57
33
|
*
|
|
58
|
-
* @example
|
|
59
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
60
|
-
* const fs = require('fs');
|
|
61
|
-
*
|
|
62
|
-
* // Instantiate Rekognition client.
|
|
63
|
-
* const client = new AWSRekognitionClient({
|
|
64
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
65
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
66
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
67
|
-
* });
|
|
68
|
-
*
|
|
69
|
-
* // Compare faces from path.
|
|
70
|
-
* await client.compareFaces('img1.jpg', 'img2.jpg');
|
|
71
|
-
*
|
|
72
|
-
* // Compare faces from data URL.
|
|
73
|
-
* await client.compareFaces('data:image/png;base64,/9j/4...', 'data:image/png;base64,/9j/4...');
|
|
74
|
-
*
|
|
75
|
-
* // Compare faces from buffer.
|
|
76
|
-
* await client.compareFaces(fs.readFileSync('img1.jpg'), fs.readFileSync('img1.jpg'));
|
|
77
|
-
*
|
|
78
34
|
* @param {string} img1 Image path or Data Url or image buffer.
|
|
79
35
|
* @param {string} img2 Image path or Data Url or image buffer.
|
|
80
36
|
* @return {Promise<number>} Level of confidence that the faces match.
|
|
@@ -87,26 +43,6 @@ export default class {
|
|
|
87
43
|
* Then, a user can search the collection for faces in the user-specific container.
|
|
88
44
|
* Note that Collection names are case-sensitive.
|
|
89
45
|
*
|
|
90
|
-
* @example
|
|
91
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
92
|
-
*
|
|
93
|
-
* // Instantiate Rekognition client.
|
|
94
|
-
* const client = new AWSRekognitionClient({
|
|
95
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
96
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
97
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
98
|
-
* });
|
|
99
|
-
*
|
|
100
|
-
* try {
|
|
101
|
-
* // Creates a collection.
|
|
102
|
-
* await client.createCollection('MyCollection');
|
|
103
|
-
* } catch(err) {
|
|
104
|
-
* // You can get the resulting HTTP status code from the exception.
|
|
105
|
-
* console.log(`name: ${err.name}`);
|
|
106
|
-
* console.log(`statusCode: ${err.statusCode}`);
|
|
107
|
-
* console.log(`message: ${err.message}`);
|
|
108
|
-
* }
|
|
109
|
-
*
|
|
110
46
|
* @param {string} collectionId ID for the collection that you are creating.
|
|
111
47
|
* The maximum length is 255, and the characters that can be used are "[a-zA-Z0-9_.\-]+".
|
|
112
48
|
*/
|
|
@@ -114,23 +50,6 @@ export default class {
|
|
|
114
50
|
/**
|
|
115
51
|
* Returns list of collection IDs.
|
|
116
52
|
*
|
|
117
|
-
* @example
|
|
118
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
119
|
-
*
|
|
120
|
-
* // Instantiate Rekognition client.
|
|
121
|
-
* const client = new AWSRekognitionClient({
|
|
122
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
123
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
124
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
125
|
-
* });
|
|
126
|
-
*
|
|
127
|
-
* // Find the collection IDs.
|
|
128
|
-
* // Output: [
|
|
129
|
-
* // 'MyCollection',
|
|
130
|
-
* // 'AnotherCollection'
|
|
131
|
-
* // ]
|
|
132
|
-
* await client.listCollections();
|
|
133
|
-
*
|
|
134
53
|
* @return {Promise<string[]>} An array of collection IDs.
|
|
135
54
|
*/
|
|
136
55
|
listCollections(): Promise<string[]>;
|
|
@@ -143,58 +62,6 @@ export default class {
|
|
|
143
62
|
* Note that this method is used to index one face.
|
|
144
63
|
* Throws an exception if no face is found in the input image or multiple faces are found.
|
|
145
64
|
*
|
|
146
|
-
* @example
|
|
147
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
148
|
-
* const fs = require('fs');
|
|
149
|
-
*
|
|
150
|
-
* // Instantiate Rekognition client.
|
|
151
|
-
* const client = new AWSRekognitionClient({
|
|
152
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
153
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
154
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
155
|
-
* });
|
|
156
|
-
*
|
|
157
|
-
* // Add face to collection from path.
|
|
158
|
-
* // Output: df8adc94-e888-4442-a03d-42aacd4a6cee
|
|
159
|
-
* const faceId = await client.indexFace('MyCollection', 'img.jpg', 'img.jpg');
|
|
160
|
-
* console.log(faceId);
|
|
161
|
-
*
|
|
162
|
-
* // Add face to collection from data URL.
|
|
163
|
-
* // Output: df8adc94-e888-4442-a03d-42aacd4a6cee
|
|
164
|
-
* const faceId = await client.indexFace('MyCollection', 'data:image/png;base64,/9j/4...', 'img.jpg');
|
|
165
|
-
* console.log(faceId);
|
|
166
|
-
*
|
|
167
|
-
* // Add face to collection from buffer.
|
|
168
|
-
* // Output: df8adc94-e888-4442-a03d-42aacd4a6cee
|
|
169
|
-
* const faceId = await client.indexFace('MyCollection', fs.readFileSync('img.jpg'), 'img.jpg');
|
|
170
|
-
* console.log(faceId);
|
|
171
|
-
*
|
|
172
|
-
* // If the face is not found in the image, throw an error.
|
|
173
|
-
* // Output: name: IndexFaceFaceNotFound
|
|
174
|
-
* // statusCode: 400
|
|
175
|
-
* // message: No face was found in the image
|
|
176
|
-
* try {
|
|
177
|
-
* await client.indexFace('MyCollection', 'img.jpg');
|
|
178
|
-
* } catch(err) {
|
|
179
|
-
* // You can get the resulting HTTP status code from the exception.
|
|
180
|
-
* console.log(`name: ${err.name}`);
|
|
181
|
-
* console.log(`statusCode: ${err.statusCode}`);
|
|
182
|
-
* console.log(`message: ${err.message}`);
|
|
183
|
-
* }
|
|
184
|
-
*
|
|
185
|
-
* // If multiple faces are found in the image, throw an error.
|
|
186
|
-
* // Output: name: IndexFaceMultipleFacesFound
|
|
187
|
-
* // statusCode: 400
|
|
188
|
-
* // message: Multiple faces found in the image
|
|
189
|
-
* try {
|
|
190
|
-
* await client.indexFace('MyCollection', 'img.jpg');
|
|
191
|
-
* } catch(err) {
|
|
192
|
-
* // You can get the resulting HTTP status code from the exception.
|
|
193
|
-
* console.log(`name: ${err.name}`);
|
|
194
|
-
* console.log(`statusCode: ${err.statusCode}`);
|
|
195
|
-
* console.log(`message: ${err.message}`);
|
|
196
|
-
* }
|
|
197
|
-
*
|
|
198
65
|
* @param {string} collectionId The ID of an existing collection to which you want to add the faces that are detected in the input images.
|
|
199
66
|
* @param {string} img Image path or Data Url or image buffer.
|
|
200
67
|
* @param {string} externalImageId The ID you want to assign to the faces detected in the image.
|
|
@@ -209,53 +76,6 @@ export default class {
|
|
|
209
76
|
* For a given input image, first detects the largest face in the image, and then searches the specified collection for matching faces.
|
|
210
77
|
* The operation compares the features of the input face with faces in the specified collection.
|
|
211
78
|
*
|
|
212
|
-
* @example
|
|
213
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
214
|
-
* const fs = require('fs');
|
|
215
|
-
*
|
|
216
|
-
* // Instantiate Rekognition client.
|
|
217
|
-
* const client = new AWSRekognitionClient({
|
|
218
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
219
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
220
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
221
|
-
* });
|
|
222
|
-
*
|
|
223
|
-
* // If you want to search for one face, specify 1 for the maxFaces option.
|
|
224
|
-
* // In that case, the search result will return the face data for one person.
|
|
225
|
-
* // Output: {
|
|
226
|
-
* // faceId: '2ce7f471-9c4b-4f27-b5a4-bbd02a5e134d',
|
|
227
|
-
* // boundingBox: {
|
|
228
|
-
* // width: 0.500495970249176,
|
|
229
|
-
* // height: 0.6926820278167725,
|
|
230
|
-
* // left: 0.2928670048713684,
|
|
231
|
-
* // top: 0.09095799922943115
|
|
232
|
-
* // },
|
|
233
|
-
* // externalImageId: 'img.jpg'
|
|
234
|
-
* // }
|
|
235
|
-
* const match = await client.searchFaces('MyCollection', 'img.jpg', {minConfidence: 99, maxFaces: 1});
|
|
236
|
-
* console.log(match);
|
|
237
|
-
*
|
|
238
|
-
* // If you want to search for multiple faces, specify 2 or more for the maxFaces option.
|
|
239
|
-
* // In that case, the search results will return a list of the face data of multiple people found.
|
|
240
|
-
* // Output: [
|
|
241
|
-
* // {
|
|
242
|
-
* // faceId: '2ce7f471-9c4b-4f27-b5a4-bbd02a5e134d',
|
|
243
|
-
* // boundingBox: {
|
|
244
|
-
* // width: 0.500495970249176,
|
|
245
|
-
* // height: 0.6926820278167725,
|
|
246
|
-
* // left: 0.2928670048713684,
|
|
247
|
-
* // top: 0.09095799922943115
|
|
248
|
-
* // },
|
|
249
|
-
* // externalImageId: 'img.jpg'
|
|
250
|
-
* // }
|
|
251
|
-
* // ]
|
|
252
|
-
* const matches = await client.searchFaces('MyCollection', 'img.jpg', {minConfidence: 99, maxFaces: 5});
|
|
253
|
-
* console.log(matches);
|
|
254
|
-
*
|
|
255
|
-
* // The input image can specify a buffer or DataURL in addition to the image path.
|
|
256
|
-
* await client.searchFaces('MyCollection', 'data:image/png;base64,/9j/4...');
|
|
257
|
-
* await client.searchFaces('MyCollection', fs.readFileSync('img.jpg'));
|
|
258
|
-
*
|
|
259
79
|
* @param {string} collectionId ID of the collection to search.
|
|
260
80
|
* @param {string} img Image path or Data Url or image buffer.
|
|
261
81
|
* @param {object} options option.
|
|
@@ -276,33 +96,6 @@ export default class {
|
|
|
276
96
|
* Returns metadata for faces in the specified collection.
|
|
277
97
|
* This metadata includes information such as the bounding box coordinates, and face ID.
|
|
278
98
|
*
|
|
279
|
-
* @example
|
|
280
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
281
|
-
* const fs = require('fs');
|
|
282
|
-
*
|
|
283
|
-
* // Instantiate Rekognition client.
|
|
284
|
-
* const client = new AWSRekognitionClient({
|
|
285
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
286
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
287
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
288
|
-
* });
|
|
289
|
-
*
|
|
290
|
-
* // Find all face metadata in the collection.
|
|
291
|
-
* // Output: [
|
|
292
|
-
* // {
|
|
293
|
-
* // faceId: '2ce7f471-9c4b-4f27-b5a4-bbd02a5e134d',
|
|
294
|
-
* // boundingBox: {
|
|
295
|
-
* // width: 0.500495970249176,
|
|
296
|
-
* // height: 0.6926820278167725,
|
|
297
|
-
* // left: 0.2928670048713684,
|
|
298
|
-
* // top: 0.09095799922943115
|
|
299
|
-
* // },
|
|
300
|
-
* // externalImageId: 'img.jpg'
|
|
301
|
-
* // }
|
|
302
|
-
* // ]
|
|
303
|
-
* const result = await client.listFaces('MyCollection');
|
|
304
|
-
* console.log(result);
|
|
305
|
-
*
|
|
306
99
|
* @param {string} collectionId ID of the collection from which to list the faces.
|
|
307
100
|
* @param {number} maxResults Maximum number of faces to return.
|
|
308
101
|
* The default value is 1000.
|
|
@@ -313,19 +106,6 @@ export default class {
|
|
|
313
106
|
* Deletes faces from a collection.
|
|
314
107
|
* You specify a collection ID and an array of face IDs to remove from the collection.
|
|
315
108
|
*
|
|
316
|
-
* @example
|
|
317
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
318
|
-
*
|
|
319
|
-
* // Instantiate Rekognition client.
|
|
320
|
-
* const client = new AWSRekognitionClient({
|
|
321
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
322
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
323
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
324
|
-
* });
|
|
325
|
-
*
|
|
326
|
-
* // Delete a face from the collection.
|
|
327
|
-
* await client.deleteFaces('MyCollection', ['f7befa24-3b83-43cc-b21f-7fac4b91f51d']);
|
|
328
|
-
*
|
|
329
109
|
* @param {string} collectionId Collection from which to remove the specific faces.
|
|
330
110
|
* @param {string[]} faceIds An array of face IDs to delete.
|
|
331
111
|
*/
|
|
@@ -334,24 +114,12 @@ export default class {
|
|
|
334
114
|
* Deletes the specified collection.
|
|
335
115
|
* Note that this operation removes all faces in the collection.
|
|
336
116
|
*
|
|
337
|
-
* @example
|
|
338
|
-
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
339
|
-
*
|
|
340
|
-
* // Instantiate Rekognition client.
|
|
341
|
-
* const client = new AWSRekognitionClient({
|
|
342
|
-
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
343
|
-
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
344
|
-
* region: process.env.AWS_REKOGNITION_REGION
|
|
345
|
-
* });
|
|
346
|
-
*
|
|
347
|
-
* // Delete collection.
|
|
348
|
-
* await client.deleteCollection('MyCollection');
|
|
349
|
-
*
|
|
350
117
|
* @param {string} collectionId ID of the collection to delete.
|
|
351
118
|
*/
|
|
352
119
|
deleteCollection(collectionId: string): Promise<void>;
|
|
353
120
|
/**
|
|
354
|
-
* Returns a buffer of images
|
|
121
|
+
* Returns a buffer of images.
|
|
122
|
+
*
|
|
355
123
|
* @param {string|Buffer} img Image path or Data Url or image buffer.
|
|
356
124
|
* @return {Buffer} Image buffer.
|
|
357
125
|
*/
|