uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

Azure Face API #253

Open uniquejava opened 5 years ago

uniquejava commented 5 years ago

https://azure.microsoft.com/en/services/cognitive-services/face/

uniquejava commented 5 years ago

cyper 的CURL实战笔记

Azure face api

Detect, identify, analyze, organize, and tag faces in photos

30,000 transactions, 20 per minute.

Endpoint: https://westcentralus.api.cognitive.microsoft.com/face/v1.0

Key 1:

Key 2:

Quick-start Guide

Create large person group

curl -si -X PUT "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/largepersongroups/<some_group_id>" \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <some_key1>" \
-d '{"name":"super group"}'

Add person

curl -si -X POST "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/largepersongroups/<some_group_id>/persons" \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <some_key1>" \
-d '{"name":"Xxx Yin", "userData":"userId=some_private_id"}'

{"personId":"<some_person_id>"}

Add face

curl -si -X POST "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/largepersongroups/<some_group_id>/persons/<some_person_id>/persistedfaces"
-H "Content-Type: application/json"
-H "Ocp-Apim-Subscription-Key: <some_key1>"

Train large person group

必须指定content-type=0

curl -si -X POST "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/largepersongroups/<some_group_id>/train" \
-H "Content-Length: 0" \
-H "Ocp-Apim-Subscription-Key: <some_key1>"

Get large person group train status

curl -si "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/largepersongroups/<some_group_id>/training" \
-H "Ocp-Apim-Subscription-Key: <some_key1>"

Get persons

curl -si https://westcentralus.api.cognitive.microsoft.com/face/v1.0/largepersongroups/<some_group_id>/persons?top=1000 \
-H "Ocp-Apim-Subscription-Key: <some_key1>"

[{
  "personId": "<some_person_id>",
  "persistedFaceIds": ["<some_face_id1>", "<some_face_id2>"],
  "name": "xxx yin",
  "userData": "userId=some_private_id"
}, {
  "personId": "<some_person_id>",
  "persistedFaceIds": ["<some_face_id>"],
  "name": "nobody noname",
  "userData": "userId=some_private_id"
}]

Face detect

必须加content-type, 必须用--data-binary参数.

curl -si -X POST https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect\?returnFaceId\=true\&returnFaceLandmarks\=false \
-H "Ocp-Apim-Subscription-Key: <some_key1>" \
-H "Content-Type: application/octet-stream" \
--data-binary "@/Users/xxx/Pictures/xxxx/IMG_3793.jpg"

[{"faceId":"<some_defected_face_id>","faceRectangle":{"top":1100,"left":580,"width":1122,"height":1122}}]%

Identify a face

curl -si -X POST "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/identify" \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <some_key1>" \
-d '{"largePersonGroupId":"<some_group_id>","faceIds":["<some_defected_face_id>"], "maxNumOfCandidatesReturned": 5,"confidenceThreshold": 0.5}'

[{"faceId":"<some_defected_face_id>","candidates":[{"personId":"<some_person_id>","confidence":0.90449},{"personId":"<some_other_person_id>","confidence":0.77416}]}]