简体   繁体   English

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

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

I want to use Google cloud Vision for detecting image properties. 我想使用Google cloud Vision检测图像属性。 I have created an account with Google Cloud and found the exact solution on one of their code snippet here ( https://cloud.google.com/vision/docs/detecting-properties#vision-image-property-detection-gcs-php ). 我已经在Google Cloud上创建了一个帐户,并在此处的其中一个代码段中找到了确切的解决方案( https://cloud.google.com/vision/docs/detecting-properties#vision-image-property-detection-gcs-php )。

I copied and adjust it to what I want to achieve. 我复制并调整到我想要实现的目标。 I installed their package using composer google/cloud-vision . 我使用作曲家google/cloud-vision安装了他们的软件包。

So here is my code: 所以这是我的代码:

<?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); 


?> 

So when I run my code it throws this error: 因此,当我运行代码时,它将引发以下错误:

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

Now am wondering what is the next step for me, also what will be my 现在我想知道下一步对我来说,那将是我的下一步
$projectId = 'YOUR_PROJECT_ID'

*Please, if this question needs more explanation let me know in the comment instead of downvoting. *请,如果这个问题需要更多解释,请在评论中让我知道,而不要投票。

Thanks. 谢谢。

@Abiodun Adetona @阿比敦·阿迪托纳

Project-Id : This is the private key, we've to generate using Google cloud vision for example - https://cloud.google.com/vision/docs/libraries#client-libraries-install-php Project-Id:这是私钥,例如,我们必须使用Google Cloud vision生成-https: //cloud.google.com/vision/docs/libraries#client-libraries-install-php

As per the error, we can say it's not able to find your file - Google\\Cloud\\Samples\\Vision; 根据错误,我们可以说它找不到您的文件Google\\Cloud\\Samples\\Vision;

To avoid this we've to load require __DIR__ . '/vendor/autoload.php'; 为了避免这种情况,我们必须加载require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php'; file before using them 使用之前先归档

namespace Google\Cloud\Samples\Vision;

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

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