【发布时间】:2017-10-06 00:38:53
【问题描述】:
我在此处遵循有关如何从 Microsoft Vision API 获取图像标签的说明: https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts/php
我设法获得了一个有效的 CURL 正文响应,如下所示:
{
"tags": [
{
"name": "person",
"confidence": 0.98979085683822632
},
{
"name": "man",
"confidence": 0.94493889808654785
},
{
"name": "outdoor",
"confidence": 0.938492476940155
},
{
"name": "window",
"confidence": 0.89513939619064331
}
]
}
我尝试foreach 标签,但我遇到了麻烦。
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("\n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag value is above 0.9, than show/echo it, do something with it
}
我无法回显任何标签。我只想显示值大于 0.9 的标签名称。比如:如果标签置信度 > 0.9,回显它,用它做点什么。
【问题讨论】:
标签: php azure curl microsoft-cognitive