PHP-谷歌视觉API-找不到类



我在尝试使用google vision API 时收到此错误消息

Fatal error: Uncaught Error: Class 'GoogleCloudVisionVisionClient' not found in C:xampphtdocsindex.php:7 Stack trace: #0 {main} thrown in C:xampphtdocsindex.php on line 7

我在windows上使用examplep。我使用composer(作为管理员(安装了Google api

composer require google/cloud-vision

我还运行(作为管理员(

composer install
composer update

谷歌云sdk已安装。

这是我的代码

<?php
require 'C:UsersMyUservendorautoload.php';
use GoogleCloudVisionVisionClient;
$path = 'caption.jpg';
$vision = new VisionClient([
'projectId' => 'my-project-numbers',
'keyFilePath' => 'my-key.json'
]);
// Annotate an image, detecting faces.
$image = $vision->image(
fopen($path, 'r'),
['text']
);
$tadaa = $vision->annotate($image);
echo '<pre>';
var_dump($tadaa->text());
echo '</pre>';
?>

根据官方文档,我建议使用以下php客户端库:

# imports the Google Cloud client library
use GoogleCloudVisionV1ImageAnnotatorClient;

快速启动:使用客户端库Vision Api

在某些情况下,问题似乎与权限有关。在一个开发服务器中,我遇到了@theepp报告的同样问题,但我可以通过更改vendor文件夹的权限来解决。

chmod 775*-R

使用https://cloud.google.com/vision/docs/ocr

以下是index.php

<?php
namespace GoogleCloudSamplesVision;
use GoogleCloudVisionV1ImageAnnotatorClient;
$path = 'caption.jpg';
$imageAnnotator = new ImageAnnotatorClient();
# annotate the image
$image = file_get_contents($path);
$response = $imageAnnotator->textDetection($image);
$texts = $response->getTextAnnotations();
printf('%d texts found:' . PHP_EOL, count($texts));
foreach ($texts as $text) {
print($text->getDescription() . PHP_EOL);
# get bounds
$vertices = $text->getBoundingPoly()->getVertices();
$bounds = [];
foreach ($vertices as $vertex) {
$bounds[] = sprintf('(%d,%d)', $vertex->getX(), $vertex->getY());
}
print('Bounds: ' . join(', ', $bounds) . PHP_EOL);
}
$imageAnnotator->close();
?>

我仍然有

Fatal error: Uncaught Error: Class 'GoogleCloudVisionV1ImageAnnotatorClient' not found in C:xampphtdocsindex.php:8 Stack trace: #0 {main} thrown in C:xampphtdocsindex.php on line 8

这是composer.json

{
"require": {
"google/cloud-vision": "^1.2"
}
}

相关内容

  • 没有找到相关文章

最新更新