[0314]_Azure_API_2写真のcompare_1★

import httplib, urllib, base64, json

###############################################
#### Update or verify the following values. ###
###############################################

# Replace the subscription_key string value with your valid subscription key.
subscription_key = ’13hc777******************8df7156′

# 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’

# Request headers.
headers = {
‘Content-Type’: ‘application/json’,
‘Ocp-Apim-Subscription-Key’: ‘91723b******************36914b9’,
}

# Request parameters.
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.******************_20170731/files/20110826oresama.JPG’}”
#body = “{‘url’:’http://153.126.******************20170731/files/1448158857484.jpg’}”
#body = “{‘url’:’http://153.126.******************/20110826文子.JPG’}”
#★(1)2つのfaceIdをbodyに入れる★#
body = “{‘faceId1’: ‘c2d3eb1f-*************786a5f851’ , ‘faceId2’: ‘1a58f491-d***************-b25d-f5375ed6f6c3’}”

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)
#★(2)detect?%をverify?にする★#
conn.request(“POST”, “/face/v1.0/verify?%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()

except Exception as e:
print(“[Errno {0}] {1}”.format(e.errno, e.strerror))

*************************
https://azure.microsoft.com/ja-jp/services/cognitive-services/face/
*************************
https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523a
*************************

*************************
http://153.126.154.******************/files/20110826oresama.JPG
“faceId1”: “c2d3eb1f-8798-43e5-bf75-fa9786a5f851”
http://153.126.154.******************170731/files/1448158857484.jpg
“faceId2”: “1a58f491-******************-b25d-f5375ed6f6c3”

あれ??あっさり出た??★★★★
[root@ik1-313-16602 verify_20170828]# python 20170828_veri3.py
Response:
{
“confidence”: 0.79488,
“isIdentical”: true
}

*************************
違う写真使ってみる。
python 20170828_veri4.py
body = “{‘url’:’http://153.126.154.106/photo_check_20170731/files/20170828_oosawa.jpg’}”
“faceId”: “c27dc17c-******************-f457db090cfc”,
これを比べる、、と????★★★★
[root@ik1-313-16602 verify_20170828]# python ******************comp.py
Response:
{
“confidence”: 0.24269,
“isIdentical”: false
}
おおお!違う、、、と!OKやな!

*************************
作業場所
/var/www/html/verify_20170828
ファイルたち
-rw-r–r– 1 root root 1917 8月 28 21:19 2017 20170828_veri1.py
-rw-r–r– 1 root root 1915 8月 28 21:25 2017 20170828_veri2.py
-rw-r–r– 1 root root 2195 8月 28 21:34 2017 20170828_veri3_comp.py
-rw-r–r– 1 root root 2005 8月 28 21:44 2017 20170828_veri4.py
-rw-r–r– 1 root root 2308 8月 28 21:48 2017 20170828_veri5_comp.py
*************************