我正在尝试使用 cURL 和 PHP 从 Clarifai 图像识别中获取标签。
在他们的网站上有一个用户指南:https://developer.clarifai.com/guide/#authentication
问题更新
我成功获取了有效的响应,看起来是这样的:
{ "status": { "code": 10000, "description": "Ok" }, "outputs": [ { "id": "ea68cac87c304b28a8046557062f34a0", "status": { "code": 10000, "description": "Ok" }, "created_at": "2016-11-22T16:50:25Z", "model": { "name": "general-v1.3", "id": "aaa03c23b3724a16a56b629203edc62c", "created_at": "2017-08-09T17:11:39Z", "app_id": null, "output_info": { "message": "Show output_info with: GET /models/{model_id}/output_info", "type": "concept" }, "model_version": { "id": "aa9ca48295b37401f8af92ad1af0d91d", "created_at": "2016-07-13T01:19:12Z", "status": { "code": 21100, "description": "Model trained successfully" } } }, "input": { "id": "ea68cac87c304b28a8046557062f34a0", "data": { "image": { "url": "https://samples.clarifai.com/metro-north.jpg" } } }, "data": { "concepts": [ { "id": "ai_HLmqFqBf", "name": "train", "app_id": null, "value": 0.9989112 }, { "id": "ai_fvlBqXZR", "name": "railway", "app_id": null, "value": 0.9975532 }, { "id": "ai_VSVscs9k", "name": "terminal", "app_id": null, "value": 0.9230834 } ] } } ]}
现在,我尝试遍历标签:
$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 { // 遍历标签,如果标签值高于93,则显示/输出它 }
但是我无法遍历标签,无法输出任何标签,我希望只显示值高于例如93的标签名称。
回答:
尝试:
CURLOPT_CUSTOMREQUEST => “POST”
Authorization: Key f26b16808e2a440abb5f28b1c00b6nnn (无括号)
然后
CURLOPT_POSTFIELDS => “{ \”inputs\”: [ { \”data\”: { \”image\”: { \”url\”: \”https://samples.clarifai.com/metro-north.jpg\” } } } ] }
基本上需要匹配此处 cURL 列中的格式:https://developer.clarifai.com/guide/predict#predict