Azure、Face API、顔検証をやってみる
https://azure.microsoft.com/ja-jp/services/cognitive-services/face/
https://azure.microsoft.com/ja-jp/services/cognitive-services/face/
1.まず俺の写真3枚準備
2.では、まずWebそのまま利用で行きましょう。
(図1)
2.では、まずWebそのまま利用で行きましょう。
(図1)
あれ、いきなり同一人物、、、だと。
3.では、データは良しとして、PHPでやってみるか。
https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236
まずは、test_consoleで。
Keyは、取り直し
(図2)
https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236
まずは、test_consoleで。
Keyは、取り直し
(図2)
(図3)
30日だけ利用可能なのね。。
保管場所は、
http://153.126.154.106/photo_check_20170731/files/
に
http://153.126.154.106/photo_check_20170731/files/IMG_15875604182662.jpeg
http://153.126.154.106/photo_check_20170731/files/1448158857484.jpg
http://153.126.154.106/photo_check_20170731/files/20110826oresama.JPG
http://153.126.154.106/photo_check_20170731/files/
に
http://153.126.154.106/photo_check_20170731/files/IMG_15875604182662.jpeg
http://153.126.154.106/photo_check_20170731/files/1448158857484.jpg
http://153.126.154.106/photo_check_20170731/files/20110826oresama.JPG
(図4)
まあ、なんか出たけど(北京でのビール片手)。。。2枚の比較ではないなあ・・・
Pragma: no-cache
apim-request-id: e0dc48de-9307-4c7e-9265-b397fb1c56dc
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Cache-Control: no-cache
Date: Mon, 31 Jul 2017 12:38:30 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 1329
Content-Type: application/json; charset=utf-8
Expires: -1
apim-request-id: e0dc48de-9307-4c7e-9265-b397fb1c56dc
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Cache-Control: no-cache
Date: Mon, 31 Jul 2017 12:38:30 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 1329
Content-Type: application/json; charset=utf-8
Expires: -1
[
{
“faceId”: “6d53a149-8c7e-4653-bbb8-1d616e6e47f3”,
“faceRectangle”: {
“top”: 151,
“left”: 863,
“width”: 406,
“height”: 406
},
“faceLandmarks”: {
“pupilLeft”: {
“x”: 980.8,
“y”: 254.3
},
“pupilRight”: {
“x”: 1154.7,
“y”: 261.1
},
“noseTip”: {
“x”: 1058.6,
“y”: 370.2
},
“mouthLeft”: {
“x”: 993.0,
“y”: 452.8
},
“mouthRight”: {
“x”: 1142.6,
“y”: 455.2
},
“eyebrowLeftOuter”: {
“x”: 920.5,
“y”: 219.1
},
“eyebrowLeftInner”: {
“x”: 1030.2,
“y”: 216.0
},
“eyeLeftOuter”: {
“x”: 953.8,
“y”: 257.4
},
“eyeLeftTop”: {
“x”: 979.6,
“y”: 244.6
},
“eyeLeftBottom”: {
“x”: 977.9,
“y”: 266.2
},
“eyeLeftInner”: {
“x”: 1002.6,
“y”: 259.1
},
“eyebrowRightInner”: {
“x”: 1089.5,
“y”: 221.5
},
“eyebrowRightOuter”: {
“x”: 1218.4,
“y”: 224.0
},
“eyeRightInner”: {
“x”: 1129.3,
“y”: 265.1
},
“eyeRightTop”: {
“x”: 1155.0,
“y”: 250.2
},
“eyeRightBottom”: {
“x”: 1154.4,
“y”: 274.1
},
“eyeRightOuter”: {
“x”: 1179.9,
“y”: 264.2
},
“noseRootLeft”: {
“x”: 1045.6,
“y”: 267.7
},
“noseRootRight”: {
“x”: 1085.5,
“y”: 269.2
},
“noseLeftAlarTop”: {
“x”: 1028.8,
“y”: 334.3
},
“noseRightAlarTop”: {
“x”: 1099.8,
“y”: 336.9
},
“noseLeftAlarOutTip”: {
“x”: 1005.2,
“y”: 370.7
},
“noseRightAlarOutTip”: {
“x”: 1123.9,
“y”: 376.6
},
“upperLipTop”: {
“x”: 1061.1,
“y”: 435.9
},
“upperLipBottom”: {
“x”: 1061.5,
“y”: 451.6
},
“underLipTop”: {
“x”: 1060.8,
“y”: 458.3
},
“underLipBottom”: {
“x”: 1060.2,
“y”: 475.9
}
},
“faceAttributes”: {
“emotion”: {
“anger”: 0.0,
“contempt”: 0.001,
“disgust”: 0.0,
“fear”: 0.0,
“happiness”: 0.123,
“neutral”: 0.876,
“sadness”: 0.0,
“surprise”: 0.0
}
}
}
]
Face List IDとやらが必要なので作れと。
https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524b/console
https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524b/console
これも一応結果出たけど・・
Pragma: no-cache
apim-request-id: f7a884b5-110d-4748-b603-2794c9a9d7d5
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Cache-Control: no-cache
Date: Mon, 31 Jul 2017 12:47:03 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 0
Expires: -1
apim-request-id: f7a884b5-110d-4748-b603-2794c9a9d7d5
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Cache-Control: no-cache
Date: Mon, 31 Jul 2017 12:47:03 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 0
Expires: -1
pythonでやってみるか、、、せっかくなんで。。。similarはサンプルコード無いみたいだな・・・残念。。
*********************************
ここからPython2.7 のコード
*********************************
ここからPython2.7 のコード
*********************************
import httplib, urllib, base64, json
###############################################
#### Update or verify the following values. ###
###############################################
#### Update or verify the following values. ###
###############################################
# Replace the subscription_key string value with your valid subscription key.
subscription_key = ’13hc77781f7e4b19b5fcdd72a8df7156′
subscription_key = ’13hc77781f7e4b19b5fcdd72a8df7156′
# Replace or verify the region.
#
# You must use the same region in your REST API call as you used to obtain your subscription keys.
# For example, if you obtained your subscription keys from the westus region, replace
# “westcentralus” in the URI below with “westus”.
#
# NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
# a free trial subscription key, you should not need to change this region.
uri_base = ‘westcentralus.api.cognitive.microsoft.com’
#
# You must use the same region in your REST API call as you used to obtain your subscription keys.
# For example, if you obtained your subscription keys from the westus region, replace
# “westcentralus” in the URI below with “westus”.
#
# NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
# a free trial subscription key, you should not need to change this region.
uri_base = ‘westcentralus.api.cognitive.microsoft.com’
# Request headers.
headers = {
‘Content-Type’: ‘application/json’,
‘Ocp-Apim-Subscription-Key’: 91723b068b294bb7b1e78d8ba36914b9,
}
headers = {
‘Content-Type’: ‘application/json’,
‘Ocp-Apim-Subscription-Key’: 91723b068b294bb7b1e78d8ba36914b9,
}
# Request parameters.
params = urllib.urlencode({
‘returnFaceId’: ‘true’,
‘returnFaceLandmarks’: ‘false’,
‘returnFaceAttributes’: ‘age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise’,
})
params = urllib.urlencode({
‘returnFaceId’: ‘true’,
‘returnFaceLandmarks’: ‘false’,
‘returnFaceAttributes’: ‘age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise’,
})
# The URL of a JPEG image to analyze.
body = “{‘url’:’http://153.126.154.106/photo_check_20170731/files/20110826oresama.JPG’}”
body = “{‘url’:’http://153.126.154.106/photo_check_20170731/files/20110826oresama.JPG’}”
try:
# Execute the REST API call and get the response.
conn = httplib.HTTPSConnection(‘westcentralus.api.cognitive.microsoft.com’)
conn.request(“POST”, “/face/v1.0/detect?%s” % params, body, headers)
response = conn.getresponse()
data = response.read()
# Execute the REST API call and get the response.
conn = httplib.HTTPSConnection(‘westcentralus.api.cognitive.microsoft.com’)
conn.request(“POST”, “/face/v1.0/detect?%s” % params, body, headers)
response = conn.getresponse()
data = response.read()
# ‘data’ contains the JSON data. The following formats the JSON data for display.
parsed = json.loads(data)
print (“Response:”)
print (json.dumps(parsed, sort_keys=True, indent=2))
conn.close()
parsed = json.loads(data)
print (“Response:”)
print (json.dumps(parsed, sort_keys=True, indent=2))
conn.close()
except Exception as e:
print(“[Errno {0}] {1}”.format(e.errno, e.strerror))
print(“[Errno {0}] {1}”.format(e.errno, e.strerror))
*********************************
ここまでPython2.7 のコード
*********************************
↓
*********************************
ここからResponse結果
*********************************
Response:
[
{
“faceAttributes”: {
“accessories”: [],
“age”: 34.9,
“blur”: {
“blurLevel”: “high”,
“value”: 0.98
},
“emotion”: {
“anger”: 0.0,
“contempt”: 0.001,
“disgust”: 0.0,
“fear”: 0.0,
“happiness”: 0.123,
“neutral”: 0.876,
“sadness”: 0.0,
“surprise”: 0.0
},
“exposure”: {
“exposureLevel”: “goodExposure”,
“value”: 0.59
},
“facialHair”: {
“beard”: 0.4,
“moustache”: 0.1,
“sideburns”: 0.2
},
“gender”: “male”,
“glasses”: “NoGlasses”,
“hair”: {
“bald”: 0.02,
“hairColor”: [
{
“color”: “brown”,
“confidence”: 1.0
},
{
“color”: “black”,
“confidence”: 0.76
},
{
“color”: “gray”,
“confidence”: 0.29
},
{
“color”: “other”,
“confidence”: 0.18
},
{
“color”: “blond”,
“confidence”: 0.09
},
{
“color”: “red”,
“confidence”: 0.07
}
],
“invisible”: false
},
“headPose”: {
“pitch”: 0.0,
“roll”: 1.2,
“yaw”: -6.3
},
“makeup”: {
“eyeMakeup”: false,
“lipMakeup”: true
},
“noise”: {
“noiseLevel”: “medium”,
“value”: 0.61
},
“occlusion”: {
“eyeOccluded”: false,
“foreheadOccluded”: false,
“mouthOccluded”: false
},
“smile”: 0.123
},
“faceId”: “3509””3-608a-4165-be27-b9e9″”””””2f7″,
“faceRectangle”: {
“height”: 406,
“left”: 863,
“top”: 151,
“width”: 406
}
}*********************************
ここまで結果
*********************************
ここまでPython2.7 のコード
*********************************
↓
*********************************
ここからResponse結果
*********************************
Response:
[
{
“faceAttributes”: {
“accessories”: [],
“age”: 34.9,
“blur”: {
“blurLevel”: “high”,
“value”: 0.98
},
“emotion”: {
“anger”: 0.0,
“contempt”: 0.001,
“disgust”: 0.0,
“fear”: 0.0,
“happiness”: 0.123,
“neutral”: 0.876,
“sadness”: 0.0,
“surprise”: 0.0
},
“exposure”: {
“exposureLevel”: “goodExposure”,
“value”: 0.59
},
“facialHair”: {
“beard”: 0.4,
“moustache”: 0.1,
“sideburns”: 0.2
},
“gender”: “male”,
“glasses”: “NoGlasses”,
“hair”: {
“bald”: 0.02,
“hairColor”: [
{
“color”: “brown”,
“confidence”: 1.0
},
{
“color”: “black”,
“confidence”: 0.76
},
{
“color”: “gray”,
“confidence”: 0.29
},
{
“color”: “other”,
“confidence”: 0.18
},
{
“color”: “blond”,
“confidence”: 0.09
},
{
“color”: “red”,
“confidence”: 0.07
}
],
“invisible”: false
},
“headPose”: {
“pitch”: 0.0,
“roll”: 1.2,
“yaw”: -6.3
},
“makeup”: {
“eyeMakeup”: false,
“lipMakeup”: true
},
“noise”: {
“noiseLevel”: “medium”,
“value”: 0.61
},
“occlusion”: {
“eyeOccluded”: false,
“foreheadOccluded”: false,
“mouthOccluded”: false
},
“smile”: 0.123
},
“faceId”: “3509””3-608a-4165-be27-b9e9″”””””2f7″,
“faceRectangle”: {
“height”: 406,
“left”: 863,
“top”: 151,
“width”: 406
}
}*********************************
ここまで結果
*********************************
うーーーん、まあ同じ結果出たけど、、、ね。。。。。
***********************
Face API
***********************
写真に含まれる顔の検出、識別、分析、グループ化、タグ付け
30,000 トランザクション (1 分あたり 20 回)。
エンドポイント: https://westcentralus.api.cognitive.microsoft.com/face/v1.0
キー 1: 917*******************6914b9
キー 2: 192**********************2105ae
Face API
***********************
写真に含まれる顔の検出、識別、分析、グループ化、タグ付け
30,000 トランザクション (1 分あたり 20 回)。
エンドポイント: https://westcentralus.api.cognitive.microsoft.com/face/v1.0
キー 1: 917*******************6914b9
キー 2: 192**********************2105ae
***********************
Emotion API
***********************
感情認識を使用してエクスペリエンスをパーソナライズする
30,000 トランザクション (1 分あたり 20 回)。
エンドポイント: https://westus.api.cognitive.microsoft.com/emotion/v1.0
キー 1: 2998″”””””””””””””””””””””””””””1866
キー 2: 229c””””””””””””””””””””””””””””3a093b
Emotion API
***********************
感情認識を使用してエクスペリエンスをパーソナライズする
30,000 トランザクション (1 分あたり 20 回)。
エンドポイント: https://westus.api.cognitive.microsoft.com/emotion/v1.0
キー 1: 2998″”””””””””””””””””””””””””””1866
キー 2: 229c””””””””””””””””””””””””””””3a093b