require_once("conf/function.php");
/*调用配置文件*/
$config = require_once("conf/config.php");
/*获取access_token*/
$url = 'https://aip.baidubce.com/oauth/2.0/token';
$post_data['grant_type'] = 'client_credentials';
$post_data['client_id'] = $config['bdAPIKey'];
$post_data['client_secret'] = $config['bdSecretKey'];
$o = "";
foreach ($post_data as $k => $v) {
$o .= "$k=" . urlencode($v) . "&";
}
$post_data = substr($o, 0, -1);
$res = request_post($url, $post_data);
$b = json_decode($res);
/*人脸融合*/
$v1 = 'http://demo.qiaodu.net/data/plugin/24/images/v1.jpg';
$v2 = 'http://demo.qiaodu.net/data/plugin/24/images/v2.jpg';
$img_v1 = explode(',', imgToBase64($v1));
$img_v2 = explode(',', imgToBase64($v2));
$url = 'https://aip.baidubce.com/rest/2.0/face/v1/merge?access_token=' . $b->access_token;
$bodys = "{
\"image_template\":
{
\"image\":\"" . $v1 . "\",
\"image_type\":\"URL\",
\"quality_control\":\"NONE\"
},
\"image_target\":
{
\"image\":\"" . $v2 . "\",
\"image_type\":\"URL\",
\"quality_control\":\"NONE\"}
}";
//var_dump($bodys);
$res = request_post($url, $bodys);
//var_dump($res);
$c = json_decode($res, true);
$img = "data:image/jpg;base64," . $c["result"]["merge_image"];
//echo $img;
imgBase64Decode($img, true, 'images');
php利用百度人脸识别实现人脸融合的解决方案(1)image_type为URL类型
关注
打赏