如何在PHP的本地主机上正确设置Google Cloud Vision? [英] How to properly set up Google cloud vision on my localhost in PHP?

查看:132
本文介绍了如何在PHP的本地主机上正确设置Google Cloud Vision?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google cloud Vision检测图像属性.我已经在Google Cloud上创建了一个帐户,并在此处的其中一个代码段中找到了确切的解决方案(

I want to use Google cloud Vision for detecting image properties. 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-vision安装了他们的软件包.

I copied and adjust it to what I want to achieve. I installed their package using 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); 


?> 

因此,当我运行代码时,它将引发以下错误:

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

现在我想知道下一步对我来说会是什么,
$projectId = 'YOUR_PROJECT_ID'

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.

谢谢.

推荐答案

@Abiodun Adetona

@Abiodun Adetona

Project-Id:这是私钥,例如,我们必须使用Google Cloud vision生成-

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

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

As per the error, we can say it's not able to find your file - Google\Cloud\Samples\Vision;

为避免这种情况,我们必须加载 require __DIR__ . '/vendor/autoload.php';文件,然后再使用它们

To avoid this we've to load require __DIR__ . '/vendor/autoload.php'; file before using them

namespace Google\Cloud\Samples\Vision;

这篇关于如何在PHP的本地主机上正确设置Google Cloud Vision?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆