[0324]_Azure_2写真_verify_rank_DB★

http://153.126.154.106/verify_20170828/20170831_rank.php




sample

‘);

if ($dbh == null){
print(‘接続に失敗しました。
‘);
}else{
print(‘MySQL-DB接続に成功しました。
‘);
}

$sql0 = <<query($sql0);
$result0 = $stmt0->fetch(PDO::FETCH_NUM);

$sql1 = <<query($sql1);
$result = $stmt1->fetch(PDO::FETCH_NUM);

$sql2 = ‘SELECT count(*) FROM verify_t_rank ‘;
$stmt2 = $dbh->query($sql2);
$result2 = $stmt2->fetch(PDO::FETCH_NUM);

$sql3 = ‘SELECT rank FROM verify_t_rank WHERE (id = (select MAX( id ) from verify_t))’;
$stmt3 = $dbh->query($sql3);
$result3 = $stmt3->fetch(PDO::FETCH_NUM);

print(‘
‘);
//print(‘#1—- :’.$result[0].”
“);
//print(‘#2—- :’.$result[1].”
“);
//print(‘#3—- :’.$result[2].”
“);
//print(‘#4—- :’.$result[3].”
“);

//print(‘#4—- :’.$result3[0].”
“);

print(‘このPhotoは、全’.$result2[0].”件のうち
“);
print(‘第 ‘.$result3[0].”位で似ています!
“);

$sql4 = ‘select * from verify_t_rank’;
$stmt4 = $dbh->query($sql4);

print(‘
verify_t_rankテーブル全表示
‘);

?>

fetch(PDO::FETCH_NUM)){
print(‘

‘);
print(‘

‘);
// print(‘

‘);

print(‘

‘);
print(‘

‘);
print(‘

‘);
print(‘

‘);
print(‘

‘);
print(‘

‘);
}
?>

id photo1 photo2 BL conf rank
‘.$result4[0].’ ‘.$result4[1].’ ‘.’‘.”.$result4[1].’ ‘.’‘.”.$result4[1].’ ‘.$result4[3].’ ‘.$result4[4].’ ‘.$result4[5].’

getMessage());
die();
}

$dbh = null;

echo ‘
MySQL-DBクローズしました’;

?>


[0323]_Azure_2写真_第〇位で似ていますDB★

///////
//SELECT display
///////
$sql0 = <<query($sql0);
$result0 = $stmt0->fetch(PDO::FETCH_NUM);

$sql1 = <<query($sql1);
$result = $stmt1->fetch(PDO::FETCH_NUM);

$sql2 = ‘SELECT count(*) FROM verify_t_rank ‘;
$stmt2 = $dbh->query($sql2);
$result2 = $stmt2->fetch(PDO::FETCH_NUM);

$sql3 = ‘SELECT rank FROM verify_t_rank WHERE (id = (select MAX( id ) from verify_t))’;
$stmt3 = $dbh->query($sql3);
$result3 = $stmt3->fetch(PDO::FETCH_NUM);

print(‘
‘);

print(‘このPhoto比較は、全’.$result2[0].”件のうち
“);
print(‘第 ‘.$result3[0].”位で似ています!
“);

///////

[0322]_Azure_2写真_verify_DB構築★

***************
‘);

if ($dbh == null){
print(‘接続に失敗しました。
‘);
}else{
print(‘MySQL-DB接続に成功しました。
‘);
}
***************
$sql = “INSERT INTO emo_list (dt_stamp, photo1, photo1fid, photo2, photo2fid, BL, conf, memo) VALUES (now(), :fn1, :reface1, :fn2, :reface2, :BL, :conf, ‘data 2017/08/31’)”;

// 挿入する値は空のまま、SQL実行の準備をする
$stmt = $dbh->prepare($sql);

// 挿入する値を配列に格納する
$params = array(‘:fn1’ => $fn1, ‘:reface1’ => $reface1, ‘:fn2’ => $fn2, ‘:reface2’ => $reface2, ‘:BL’ => $reisIdent2, ‘:conf’ => $reiconfi2);

// 挿入する値が入った変数をexecuteにセットしてSQLを実行
$stmt->execute($params);

***************
///////
//SELECT display
///////
$sql0 = <<query($sql0);
$result0 = $stmt0->fetch(PDO::FETCH_NUM);

$sql1 = <<query($sql1);
$result = $stmt1->fetch(PDO::FETCH_NUM);

$sql2 = ‘SELECT count(*) FROM emo_list_rank ‘;
$stmt2 = $dbh->query($sql2);
$result2 = $stmt2->fetch(PDO::FETCH_NUM);

$sql3 = ‘SELECT rank FROM emo_list_rank WHERE (id = (select MAX( id ) from emo_list))’;
$stmt3 = $dbh->query($sql3);
$result3 = $stmt3->fetch(PDO::FETCH_NUM);

print(‘
‘);

print(‘このPhotoは、全’.$result2[0].”件のうち
“);
print(‘第 ‘.$result3[0].”位のHappiness度です!
“);

***************
}

}

// 配列じゃなかったらエラーメッセージを表示
} else {
echo ‘ありません。’;
}

// 登録完了のメッセージ
echo ‘
MySQL-DB登録完了しました’;

}catch (PDOException $e){
print(‘Error:’.$e->getMessage());
die();
}

$dbh = null;

?>

[0321]_Azure_2写真「無料切れ」再度API取得★

********************************************
20180830FaceEmotion
3239e067************0f5b0590b28
4b843e2************b344d71fb05
リファレンス
https://dev.projectoxford.ai/docs/services/563879***********be8d/op***********ns/563879b***********5236
ファイルURL
http://153.126.154.106/verify_20170828/files/201************a.JPG
********************************************
[1]
subscription_key = ‘3239e0************0b28’

[2]
# Request headers.
headers = {
‘Content-Type’: ‘application/json’,
# ‘Ocp-Apim-Subscription-Key’: ‘91723************6914b9’,
# ‘Ocp-Apim-Subscription-Key’: ‘2ac************d9985’,
‘Ocp-Apim-Subscription-Key’: subscription_key,
}

[0320]_Azure_2写真compでpython/php連携部分を作る★

python 20170829_veri_comp_hen.py “c2d3eb1f-******************fa9786a5f851” “c27dc17c-******************-f457db090cfc”

# vi 20170828_comp_exec.php

//////////// 2 faceId compare, send to python “20170829_veri_comp_hen.py”
$fullPath_comp =
‘python ./20170829_veri_comp_hen.py ‘.$reface1.’ ‘.$reface2;
exec($fullPath_comp, $outpara_comp);
echo ‘

‘;
echo $fullPath_comp;
echo ‘

‘;

// is_array関数で配列かどうか判定する
if(is_array($outpara_comp)) {

// 配列だったらforeach関数でループ処理
foreach ($outpara_comp as $resout_comp) {
//if (strstr($resout_comp, ‘faceId’)) {
// echo ‘
‘;
//echo “
(Result of 2 files compare : )
“;
echo $resout_comp;
//$face2=$resout;
//$a=$face2;
//$b=strpos($a,”:”);
//$c=strpos($a,’,’);
//$reface2=substr($a,$b+1,$c-$b-1);
//echo $reface2;
//echo $resout;
echo ‘
‘;
//}
}
echo “compare end———————-
“;

// 配列じゃなかったらエラーメッセージを表示
} else {
echo ‘ありません。’;
}

**********************************

2011******************ama.JPGをアップロードしました。
1448******************484.jpgをアップロードしました。
———————-
file1 is : 2011******************ama.JPG
file2 is : 1448******************4.jpg
———————-
python ./20170829_pho_******************0826oresama.JPG

(file 1’s faceId is : ) “faceId”: “4ba85a51-******************-00a838247897”, “4ba85a51******************-00a838247897”
#1———————-
python ./20170829_pho_verify.py 1448158857484.jpg

(file 2’s faceId is : ) “faceId”: “9e272c64-******************-b2703e4d7747”, “9e272c64-******************-b2703e4d7747”
#2———————-
python ./20170829_veri_comp_hen.py “4ba85a51-******************-00a838247897” “9e272c64-5a12-******************b2703e4d7747”

(Result of 2 files compare : )
{‘faceId1’: ‘4ba85a51-******************-00a838247897′ ,’faceId2’: ‘9e272c64-******************b2703e4d7747’}
Response:
{
“confidence”: 0.79488,
“isIdentical”: true
}
compare end———————-

************************************

20170828******************.jpgをアップロードしました。
144815******************484.jpgをアップロードしました。
———————-
file1 is : ******************oosawa.jpg
file2 is : 1448******************7484.jpg
———————-
python ./20170829_pho_******************_oosawa.jpg

(file 1’s faceId is : ) “faceId”: “d68e07e3-******************-e7f5b1ace111”, “d68e07e3-******************-e7f5b1ace111”
#1———————-
python ./20170829_pho_verify.py 1448158857484.jpg

(file 2’s faceId is : ) “faceId”: “9e272c64-******************-b2703e4d7747”, “9e272c64-******************-b2703e4d7747”
#2———————-
python ./20170829_veri_comp_hen.py “d68e07e3-******************-e7f5b1ace111” “9e272c64-******************bf8b-b2703e4d7747”

(Result of 2 files compare : )
{‘faceId1’: ‘d68e07e3-f466-******************e7f5b1ace111′ ,’faceId2’: ‘9e272c64-******************-b2703e4d7747’}
Response:
{
“confidence”: 0.22401,
“isIdentical”: false
}
compare end———————-

************************************

[0319]_Azure_2写真compのhtml/phpを作る★

オリジナルは、、、
****************************



sample

MS_Azure_emotion_AI_htmlとupload.phpを作る
2017/08/06 Making –emotion analysis–
ファイル:




****************************
、、、だから、ここに2写真を選んでphpへ飛ばせばOKかな???

****************************

****************************
送る方20170828_pho12.html
****************************



sample

MS_Azure_2枚の写真をcompareする
2017/08/28 Making –verify analysis–
ファイル1:

ファイル2:




****************************
受ける方20170828_comp_exec.php
****************************



sample

“;
print “file2 is : “.$fn2.”
“;

?>



****************************
試す!
http://153.126.154.******************/20170828_pho12.html
一応2ファイルが/tmpのところで読めた!

この後、20170806_upload_exec1.phpを参考に、、、
・これら2ファイルを/filesに保存
・faceIdをそれぞれ取得、2つ
・これをcompareして結果を表示する
・ついでに、これもDB登録して、2ファイルの名前と結果を保存しておく。
かな。。

[0318]_Azure_2写真compare_faceIdをゲットする★

************************
20170828_comp_exec.php
************************
‘;
echo $fullPath;
echo ‘

‘;

// is_array関数で配列かどうか判定する
if(is_array($outpara)) {

// 配列だったらforeach関数でループ処理
foreach ($outpara as $resout) {

if (strstr($resout, ‘faceId’)) {
echo ‘
‘;
echo “(file 1’s faceId is : ) “;
echo $resout;
//$ange=$resout;
//$a=$ange;
//$b=strpos($a,”:”);
//$c=strpos($a,’,’);
//$ange1=substr($a,$b+1,$c-$b-1);
//echo $ange1;
echo ‘
‘;
}

//print(‘
‘);
}

echo “X———————-“;
echo $resout;
// }

// 配列じゃなかったらエラーメッセージを表示
} else {
echo ‘ありません。’;
}

?>

************************
20170829_pho_verify.py
************************
import httplib, urllib, base64, json
import sys
args = sys.argv

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

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

# 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’: ‘91723******************d8ba36914b9’,
}

# 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.******************/20110826oresama.JPG’}”

##20170806 amend parts
body = “{‘url’:’http://153.126.******************/files/”+args[1]+”‘}”
######################

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()

# ‘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))

[0317]_Azure_2写真compare_生値faceId1-2で比較★

import httplib, urllib, base64, json

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

# Replace the subscription_key string value with your valid subscription key.
subscription_key = ’13hc******************2a8df7156′

# 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’: ‘91723b068******************914b9’,
}

# 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.******************/files/20110826oresama.JPG’}”
#body = “{‘url’:’http://153.******************/files/1448158857484.jpg’}”
#body = “{‘url’:’http://153.******************/20110826文子.JPG’}”
#★(1)2つのfaceIdをbodyに入れる★#
body = “{‘faceId1’: ‘c2d3eb1f-8798-43e5-bf75-fa9786a5f851’ , ‘faceId2’: ‘1a58f491-da60-433e-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/******************1984550f3039523a
*************************

*************************
http://153.126.154.106/photo_check_20170731/files/20110826oresama.JPG
“faceId1”: “c2d3eb1f-******************-fa9786a5f851”
http://153.126.154.106/photo_check_20170731/files/1448158857484.jpg
“faceId2”: “1a58f491-******************”

あれ??あっさり出た??★★★★
[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******************_oosawa.jpg’}”
“faceId”: “c27dc17c-******************f457db090cfc”,
これを比べる、、と????★★★★
[root@ik1-313-16602 verify_20170828]# python 20170828_veri5_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
*************************

[0316]_Azure_2写真compare_faceIdの形式確認★

[root@ik1-313-16602 photo_check_20170731]# python ******************.py
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”: “c2d3eb1f******************”,
“faceRectangle”: {
“height”: 406,
“left”: 863,
“top”: 151,
“width”: 406
}
}
]

[0315]_Azure_API_2写真のcompare_2_入力フォームhtml★

オリジナルは、、、
****************************



sample

MS_Azure_emotion_AI_htmlとupload.phpを作る
2017/08/06 Making –emotion analysis–
ファイル:




****************************
、、、だから、ここに2写真を選んでphpへ飛ばせばOKかな???

****************************

****************************
送る方20170828_pho12.html
****************************



sample

MS_Azure_2枚の写真をcompareする
2017/08/28 Making –verify analysis–
ファイル1:

ファイル2:




****************************
受ける方20170828_comp_exec.php
****************************



sample

“;
print “file2 is : “.$fn2.”
“;

?>



****************************
試す!
http://153.126.154.106/verify_20170828/20170828_pho12.html
一応2ファイルが/tmpのところで読めた!

この後、20170806_upload_exec1.phpを参考に、、、
・これら2ファイルを/filesに保存
・faceIdをそれぞれ取得、2つ
・これをcompareして結果を表示する
・ついでに、これもDB登録して、2ファイルの名前と結果を保存しておく。
かな。。