本文主要是介绍php调用face++实现人脸识别自学(仅供参考),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言:要调用使用php+face++实现人脸识别先把思路清晰一下,首先要在face++我的应用里创建一个group组,在group组里创建person类(属于人)再把上传的图片放入person里(大概的思路,但是还有很多)下面开始。
第一 :进入face++官网注册一下,之后创建应用就可以看到API_key和API_secret值。
第二:如下代码(模拟一张图片的请求)
<?php
function curlPost($url,$data,$method){
$ch = curl_init(); //1.初始化
curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式
//4.参数如下
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');//模拟浏览器
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Encoding: gzip, deflate'));//gzip解压内容
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
if($method=="POST"){//5.post方式的时候添加数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);//6.执行
if (curl_errno($ch)) {//7.如果出错
return curl_error($ch);
}
curl_close($ch);//8.关闭
return $tmpInfo;
}
//(图片路径)↓
$filename="G:/phpstudy/WWW/dayi/face/zhangyushi.jpg";
$data=array
(
"api_secret"=>"写入你的值",
"api_key"=>"写入你的值",
"attribute" => "gender,age,race,smiling,glass,pose",
"img"=>new CURLFile($filename),
);
$url="http://apicn.faceplusplus.com/v2/detection/detect";
$method="POST";
$files=curlPost($url,$data,$method);
$files=json_decode($files,true);
// $face = $face_body['face'];
// $face_1 = $files['face']['0']['face_id'];
// $face_id = $face_1['face_id'];
// echo $face_1;
print_r($files);
?>
//打印一下如下效果
Array( [face] => Array ( [0] => Array ( [attribute] => Array ( [age] => Array ( [range] => 7 [value] => 29 ) [gender] => Array ( [confidence] => 99.997 [value] => Male ) [glass] => Array ( [confidence] => 97.2905 [value] => None ) [pose] => Array ( [pitch_angle] => Array ( [value] => -0.000628 ) [roll_angle] => Array ( [value] => 0.704834 ) [yaw_angle] => Array ( [value] => -0.024123 ) ) [race] => Array ( [confidence] => 99.9767 [value] => Asian ) [smiling] => Array ( [value] => 0.269433 ) ) [face_id] => fa60657aae7e788df9b909f2d2b0fcd8 [position] => Array ( [center] => Array ( [x] => 51.166667 [y] => 54.302671 ) [eye_left] => Array ( [x] => 47.139167 [y] => 48.767656 ) [eye_right] => Array ( [x] => 55.6335 [y] =>
这篇关于php调用face++实现人脸识别自学(仅供参考)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!