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 ).
I copied and adjust it to what I want to achieve. I installed their package using composer 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
As per the error, we can say it's not able to find your file - Google\\Cloud\\Samples\\Vision;
To avoid this we've to load require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';
file before using them
namespace Google\Cloud\Samples\Vision;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.