Skip to content

Commit 2e7dba1

Browse files
author
SDK Automation
committed
Update from master
1 parent 22133f4 commit 2e7dba1

File tree

9 files changed

+250
-232
lines changed

9 files changed

+250
-232
lines changed

sdk/cognitiveservices/cognitiveservices-face/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Microsoft
3+
Copyright (c) 2020 Microsoft
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

sdk/cognitiveservices/cognitiveservices-face/README.md

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,84 +17,79 @@ npm install @azure/cognitiveservices-face
1717

1818
#### nodejs - Authentication, client creation and list personGroupPerson as an example written in TypeScript.
1919

20-
##### Install @azure/ms-rest-azure-js
20+
##### Install @azure/ms-rest-nodeauth
2121

22+
- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`.
2223
```bash
23-
npm install @azure/ms-rest-azure-js
24+
npm install @azure/ms-rest-nodeauth@"^3.0.0"
2425
```
2526

2627
##### Sample code
27-
The following sample detects the facial features on the given image. To know more, refer to the [Azure Documentation on Face APIs](https://docs.microsoft.com/en-us/azure/cognitive-services/face/overview)
2828

2929
```typescript
30-
import { FaceClient, FaceModels } from "@azure/cognitiveservices-face";
31-
import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js";
32-
33-
async function main(): Promise<void> {
34-
const faceKey = process.env["faceKey"] || "<faceKey>";
35-
const faceEndPoint = process.env["faceEndPoint"] || "<faceEndPoint>";
36-
const cognitiveServiceCredentials = new CognitiveServicesCredentials(faceKey);
37-
const client = new FaceClient(cognitiveServiceCredentials, faceEndPoint);
38-
const url =
39-
"https://pbs.twimg.com/profile_images/3354326900/3a5168f2b45c07d0965098be1a4e3007.jpeg";
40-
const options: FaceModels.FaceDetectWithUrlOptionalParams = {
41-
returnFaceLandmarks: true
42-
};
43-
client.face
44-
.detectWithUrl(url, options)
45-
.then(result => {
46-
console.log("The result is: ");
47-
console.log(result);
48-
})
49-
.catch(err => {
50-
console.log("An error occurred:");
51-
console.error(err);
52-
});
53-
}
54-
55-
main();
30+
import * as msRest from "@azure/ms-rest-js";
31+
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
32+
import { FaceClient, FaceModels, FaceMappers } from "@azure/cognitiveservices-face";
33+
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
34+
35+
msRestNodeAuth.interactiveLogin().then((creds) => {
36+
const client = new FaceClient(creds, subscriptionId);
37+
const personGroupId = "testpersonGroupId";
38+
const start = "teststart";
39+
const top = 1;
40+
client.personGroupPerson.list(personGroupId, start, top).then((result) => {
41+
console.log("The result is:");
42+
console.log(result);
43+
});
44+
}).catch((err) => {
45+
console.error(err);
46+
});
5647
```
5748

5849
#### browser - Authentication, client creation and list personGroupPerson as an example written in JavaScript.
5950

51+
##### Install @azure/ms-rest-browserauth
52+
53+
```bash
54+
npm install @azure/ms-rest-browserauth
55+
```
56+
6057
##### Sample code
6158

59+
See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
60+
6261
- index.html
6362
```html
6463
<!DOCTYPE html>
6564
<html lang="en">
6665
<head>
6766
<title>@azure/cognitiveservices-face sample</title>
6867
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
68+
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
6969
<script src="node_modules/@azure/cognitiveservices-face/dist/cognitiveservices-face.js"></script>
7070
<script type="text/javascript">
71-
const faceKey = "<YOUR_FACE_KEY>";
72-
const faceEndPoint = "<YOUR_FACE_ENDPOINT>";
73-
const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
74-
inHeader: {
75-
"Ocp-Apim-Subscription-Key": faceKey
76-
}
71+
const subscriptionId = "<Subscription_Id>";
72+
const authManager = new msAuth.AuthManager({
73+
clientId: "<client id for your Azure AD app>",
74+
tenant: "<optional tenant for your organization>"
7775
});
78-
const client = new Azure.CognitiveservicesFace.FaceClient(
79-
cognitiveServiceCredentials,
80-
faceEndPoint
81-
);
82-
83-
const url =
84-
"https://pbs.twimg.com/profile_images/3354326900/3a5168f2b45c07d0965098be1a4e3007.jpeg";
85-
const options = {
86-
returnFaceLandmarks: true
87-
};
88-
client.face
89-
.detectWithUrl(url, options)
90-
.then(result => {
91-
console.log("The result is: ");
76+
authManager.finalizeLogin().then((res) => {
77+
if (!res.isLoggedIn) {
78+
// may cause redirects
79+
authManager.login();
80+
}
81+
const client = new Azure.CognitiveservicesFace.FaceClient(res.creds, subscriptionId);
82+
const personGroupId = "testpersonGroupId";
83+
const start = "teststart";
84+
const top = 1;
85+
client.personGroupPerson.list(personGroupId, start, top).then((result) => {
86+
console.log("The result is:");
9287
console.log(result);
93-
})
94-
.catch(err => {
88+
}).catch((err) => {
9589
console.log("An error occurred:");
9690
console.error(err);
9791
});
92+
});
9893
</script>
9994
</head>
10095
<body></body>
@@ -105,4 +100,4 @@ main();
105100

106101
- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
107102

108-
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-face%2FREADME.png)
103+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-face/README.png)

sdk/cognitiveservices/cognitiveservices-face/src/operations/face.ts

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export class Face {
2929
/**
3030
* Given query face's faceId, to search the similar-looking faces from a faceId array, a face list
3131
* or a large face list. faceId array contains the faces created by [Face -
32-
* Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236), which will
33-
* expire 24 hours after creation. A "faceListId" is created by [FaceList -
34-
* Create](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524b) containing
32+
* Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl), which
33+
* will expire 24 hours after creation. A "faceListId" is created by [FaceList -
34+
* Create](https://docs.microsoft.com/rest/api/cognitiveservices/face/facelist/create) containing
3535
* persistedFaceIds that will not expire. And a "largeFaceListId" is created by [LargeFaceList -
36-
* Create](/docs/services/563879b61984550e40cbbe8d/operations/5a157b68d2de3616c086f2cc) containing
37-
* persistedFaceIds that will also not expire. Depending on the input the returned similar faces
38-
* list contains faceIds or persistedFaceIds ranked by similarity.
36+
* Create](https://docs.microsoft.com/rest/api/cognitiveservices/face/largefacelist/create)
37+
* containing persistedFaceIds that will also not expire. Depending on the input the returned
38+
* similar faces list contains faceIds or persistedFaceIds ranked by similarity.
3939
* <br/>Find similar has two working modes, "matchPerson" and "matchFace". "matchPerson" is the
4040
* default mode that it tries to find faces of the same person as possible by using internal
4141
* same-person thresholds. It is useful to find a known person's other photos. Note that an empty
@@ -83,8 +83,8 @@ export class Face {
8383
* face from original faces. The messyGroup will not appear in the result if all faces found their
8484
* counterparts.
8585
* * Group API needs at least 2 candidate faces and 1000 at most. We suggest to try [Face -
86-
* Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a) when you
87-
* only have 2 candidate faces.
86+
* Verify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/verifyfacetoface) when
87+
* you only have 2 candidate faces.
8888
* * The 'recognitionModel' associated with the query faces' faceIds should be the same.
8989
* @param faceIds Array of candidate faceId created by Face - Detect. The maximum is 1000 faces
9090
* @param [options] The optional parameters
@@ -120,9 +120,9 @@ export class Face {
120120
* (given by largePersonGroupId), and return candidate person(s) for that face ranked by similarity
121121
* confidence. The person group/large person group should be trained to make it ready for
122122
* identification. See more in [PersonGroup -
123-
* Train](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395249) and
123+
* Train](https://docs.microsoft.com/rest/api/cognitiveservices/face/persongroup/train) and
124124
* [LargePersonGroup -
125-
* Train](/docs/services/563879b61984550e40cbbe8d/operations/599ae2d16ac60f11b48b5aa4).
125+
* Train](https://docs.microsoft.com/rest/api/cognitiveservices/face/largepersongroup/train).
126126
* <br/>
127127
*
128128
* Remarks:<br />
@@ -135,7 +135,7 @@ export class Face {
135135
* * Number of candidates returned is restricted by maxNumOfCandidatesReturned and
136136
* confidenceThreshold. If no person is identified, the returned candidates will be an empty array.
137137
* * Try [Face - Find
138-
* Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237) when you
138+
* Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar) when you
139139
* need to find similar faces from a face list/large face list instead of a person group/large
140140
* person group.
141141
* * The 'recognitionModel' associated with the query faces' faceIds should be the same as the
@@ -213,11 +213,11 @@ export class Face {
213213
* and attributes.<br />
214214
* * No image will be stored. Only the extracted face feature will be stored on server. The faceId
215215
* is an identifier of the face feature and will be used in [Face -
216-
* Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239), [Face -
217-
* Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a), and [Face
218-
* - Find Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
219-
* The stored face feature(s) will expire and be deleted 24 hours after the original detection
220-
* call.
216+
* Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify), [Face -
217+
* Verify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/verifyfacetoface), and
218+
* [Face - Find
219+
* Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar). The
220+
* stored face feature(s) will expire and be deleted 24 hours after the original detection call.
221221
* * Optional parameters include faceId, landmarks, and attributes. Attributes include age, gender,
222222
* headPose, smile, facialHair, glasses, emotion, hair, makeup, occlusion, accessories, blur,
223223
* exposure and noise. Some of the results returned for specific attributes may not be highly
@@ -227,23 +227,25 @@ export class Face {
227227
* * Up to 100 faces can be returned for an image. Faces are ranked by face rectangle size from
228228
* large to small.
229229
* * For optimal results when querying [Face -
230-
* Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239), [Face -
231-
* Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a), and [Face
232-
* - Find Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237)
230+
* Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify), [Face -
231+
* Verify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/verifyfacetoface), and
232+
* [Face - Find
233+
* Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar)
233234
* ('returnFaceId' is true), please use faces that are: frontal, clear, and with a minimum size of
234235
* 200x200 pixels (100 pixels between eyes).
235236
* * The minimum detectable face size is 36x36 pixels in an image no larger than 1920x1080 pixels.
236237
* Images with dimensions higher than 1920x1080 pixels will need a proportionally larger minimum
237238
* face size.
238239
* * Different 'detectionModel' values can be provided. To use and compare different detection
239240
* models, please refer to [How to specify a detection
240-
* model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
241+
* model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
241242
* | Model | Recommended use-case(s) |
242243
* | ---------- | -------- |
243244
* | 'detection_01': | The default detection model for [Face -
244-
* Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). Recommend
245-
* for near frontal face detection. For scenarios with exceptionally large angle (head-pose) faces,
246-
* occluded faces or wrong image orientation, the faces in such cases may not be detected. |
245+
* Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl).
246+
* Recommend for near frontal face detection. For scenarios with exceptionally large angle
247+
* (head-pose) faces, occluded faces or wrong image orientation, the faces in such cases may not be
248+
* detected. |
247249
* | 'detection_02': | Detection model released in 2019 May with improved accuracy especially on
248250
* small, side and blurry faces. |
249251
*
@@ -253,12 +255,12 @@ export class Face {
253255
* please explicitly specify the model you need in this parameter. Once specified, the detected
254256
* faceIds will be associated with the specified recognition model. More details, please refer to
255257
* [How to specify a recognition
256-
* model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-recognition-model)
258+
* model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-recognition-model)
257259
* | Model | Recommended use-case(s) |
258260
* | ---------- | -------- |
259261
* | 'recognition_01': | The default recognition model for [Face -
260-
* Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). All those
261-
* faceIds created before 2019 March are bonded with this recognition model. |
262+
* Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl). All
263+
* those faceIds created before 2019 March are bonded with this recognition model. |
262264
* | 'recognition_02': | Recognition model released in 2019 March. 'recognition_02' is recommended
263265
* since its overall accuracy is improved compared with 'recognition_01'. |
264266
* @param url Publicly reachable URL of an image
@@ -327,11 +329,11 @@ export class Face {
327329
* and attributes.<br />
328330
* * No image will be stored. Only the extracted face feature will be stored on server. The faceId
329331
* is an identifier of the face feature and will be used in [Face -
330-
* Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239), [Face -
331-
* Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a), and [Face
332-
* - Find Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237).
333-
* The stored face feature(s) will expire and be deleted 24 hours after the original detection
334-
* call.
332+
* Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify), [Face -
333+
* Verify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/verifyfacetoface), and
334+
* [Face - Find
335+
* Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar). The
336+
* stored face feature(s) will expire and be deleted 24 hours after the original detection call.
335337
* * Optional parameters include faceId, landmarks, and attributes. Attributes include age, gender,
336338
* headPose, smile, facialHair, glasses, emotion, hair, makeup, occlusion, accessories, blur,
337339
* exposure and noise. Some of the results returned for specific attributes may not be highly
@@ -341,23 +343,25 @@ export class Face {
341343
* * Up to 100 faces can be returned for an image. Faces are ranked by face rectangle size from
342344
* large to small.
343345
* * For optimal results when querying [Face -
344-
* Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239), [Face -
345-
* Verify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a), and [Face
346-
* - Find Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237)
346+
* Identify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/identify), [Face -
347+
* Verify](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/verifyfacetoface), and
348+
* [Face - Find
349+
* Similar](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/findsimilar)
347350
* ('returnFaceId' is true), please use faces that are: frontal, clear, and with a minimum size of
348351
* 200x200 pixels (100 pixels between eyes).
349352
* * The minimum detectable face size is 36x36 pixels in an image no larger than 1920x1080 pixels.
350353
* Images with dimensions higher than 1920x1080 pixels will need a proportionally larger minimum
351354
* face size.
352355
* * Different 'detectionModel' values can be provided. To use and compare different detection
353356
* models, please refer to [How to specify a detection
354-
* model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
357+
* model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
355358
* | Model | Recommended use-case(s) |
356359
* | ---------- | -------- |
357360
* | 'detection_01': | The default detection model for [Face -
358-
* Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). Recommend
359-
* for near frontal face detection. For scenarios with exceptionally large angle (head-pose) faces,
360-
* occluded faces or wrong image orientation, the faces in such cases may not be detected. |
361+
* Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl).
362+
* Recommend for near frontal face detection. For scenarios with exceptionally large angle
363+
* (head-pose) faces, occluded faces or wrong image orientation, the faces in such cases may not be
364+
* detected. |
361365
* | 'detection_02': | Detection model released in 2019 May with improved accuracy especially on
362366
* small, side and blurry faces. |
363367
*
@@ -367,12 +371,12 @@ export class Face {
367371
* please explicitly specify the model you need in this parameter. Once specified, the detected
368372
* faceIds will be associated with the specified recognition model. More details, please refer to
369373
* [How to specify a recognition
370-
* model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-recognition-model)
374+
* model](https://docs.microsoft.com/azure/cognitive-services/face/face-api-how-to-topics/specify-recognition-model)
371375
* | Model | Recommended use-case(s) |
372376
* | ---------- | -------- |
373377
* | 'recognition_01': | The default recognition model for [Face -
374-
* Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). All those
375-
* faceIds created before 2019 March are bonded with this recognition model. |
378+
* Detect](https://docs.microsoft.com/rest/api/cognitiveservices/face/face/detectwithurl). All
379+
* those faceIds created before 2019 March are bonded with this recognition model. |
376380
* | 'recognition_02': | Recognition model released in 2019 March. 'recognition_02' is recommended
377381
* since its overall accuracy is improved compared with 'recognition_01'. |
378382
* @param image An image stream.

0 commit comments

Comments
 (0)