[英]PHP - how to extract text from image using 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.