问题
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.
回答1:
@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';
file before using them
namespace Google\Cloud\Samples\Vision;
来源:https://stackoverflow.com/questions/50018491/how-to-properly-set-up-google-cloud-vision-on-my-localhost-in-php