【发布时间】:2018-10-05 16:58:32
【问题描述】:
我想使用 Google Cloud Vision 来检测图像属性。我已经在 Google Cloud 上创建了一个帐户,并在此处 (https://cloud.google.com/vision/docs/detecting-properties#vision-image-property-detection-gcs-php) 的其中一个代码 sn-p 上找到了确切的解决方案。
我复制并调整它以达到我想要的效果。我使用 composer google/cloud-vision 安装了他们的包。
这是我的代码:
<?php
namespace Google\Cloud\Samples\Vision;
use Google\Cloud\Vision\VisionClient;
$projectId = 'YOUR_PROJECT_ID';
$path = 'event1.jpg';
function detect_image_property($projectId, $path)
{
$vision = new VisionClient([
'projectId' => $projectId,
]);
$image = $vision->image(file_get_contents($path), [
'IMAGE_PROPERTIES'
]);
$result = $vision->annotate($image);
print("Properties:\n");
foreach ($result->imageProperties()->colors() as $color) {
$rgb = $color['color'];
printf("red:%s\n", $rgb['red']);
printf("green:%s\n", $rgb['green']);
printf("blue:%s\n\n", $rgb['blue']);
}
}
detect_image_property($projectId, $path);
?>
所以当我运行我的代码时,它会抛出这个错误:
Fatal error: Uncaught Error: Class 'Google\Cloud\Vision\VisionClient' not found in C:\xampp\htdocs\vision\index.php:12 Stack trace: #0 C:\xampp\htdocs\vision\index.php(28): Google\Cloud\Samples\Vision\detect_image_property('YOUR_PROJECT_ID', 'event1.jpg') #1 {main} thrown in C:\xampp\htdocs\vision\index.php on line 12
现在我想知道我的下一步是什么,我的下一步是什么$projectId = 'YOUR_PROJECT_ID'
*如果这个问题需要更多解释,请在评论中告诉我,而不是投反对票。
谢谢。
【问题讨论】:
标签: php google-cloud-platform google-cloud-vision