繁体   English   中英

如何在PHP的本地主机上正确设置Google Cloud Vision?

[英]How to properly set up Google cloud vision on my localhost in PHP?

我想使用Google cloud Vision检测图像属性。 我已经在Google Cloud上创建了一个帐户,并在此处的其中一个代码段中找到了确切的解决方案( https://cloud.google.com/vision/docs/detecting-properties#vision-image-property-detection-gcs-php )。

我复制并调整到我想要实现的目标。 我使用作曲家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'

*请,如果这个问题需要更多解释,请在评论中让我知道,而不要投票。

谢谢。

@阿比敦·阿迪托纳

Project-Id:这是私钥,例如,我们必须使用Google Cloud vision生成-https: //cloud.google.com/vision/docs/libraries#client-libraries-install-php

根据错误,我们可以说它找不到您的文件Google\\Cloud\\Samples\\Vision;

为了避免这种情况,我们必须加载require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php'; 使用之前先归档

namespace Google\Cloud\Samples\Vision;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM