PHP使用微软认知服务Face API
2021-02-18 20:17
标签:post 示例 org url stream ssl证书 type 版本 ble 注意:默认的http客户端工具一般到需要证书的认证,如果没有导入相应的证书一般会报SSL证书认证错误。 PHP使用微软认知服务Face API 标签:post 示例 org url stream ssl证书 type 版本 ble 原文地址:https://www.cnblogs.com/taro/p/8329231.html
下面主要介绍基于PHP语言,基于guzzle类库,调用微软最新推出的认知服务:人脸识别。
实验环境:
1. 使用composer安装Guzzle
{
"require": {
"guzzlehttp/guzzle": "~6.0"
}
}
php composer.phar install
2. 证书安装
curl.cainfo =
3. PHP代码示例
‘application/json‘,‘Ocp-Apim-Subscription-Key‘ => ‘{key}‘];
$body = ‘{"url":"{image‘s url}"}‘;
$request = new Request(‘POST‘,‘https://api.cognitive.azure.cn/face/v1.0/detect‘, $headers , $body);
$response = $client->send($request);
echo $response->getBody();
?>
4. 运行结果示例
[{"faceId":"b22efa8f-0e34-4344-8346-ca8b79d29a27","faceRectangle":{"top":181,"left":184,"width":257,"height":257}}]
5. 读取本地图片
‘application/octet-stream‘,‘Ocp-Apim-Subscription-Key‘ => ‘bd8e4ce12f444c639ac9c214d70ac72c‘];
$myfile = fopen("tt.jpg", "r") or die("Unable to open file!");
$request = new Request(‘POST‘,‘https://api.cognitive.azure.cn/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age‘, $headers , $myfile);
$response = $client->send($request);
echo $response->getBody();
fclose($myfile);
?>
6. 更多参考
文章标题:PHP使用微软认知服务Face API
文章链接:http://soscw.com/index.php/essay/57198.html