Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

namespace GoogleCloudSamplesVision;    

require_once('../vendor/autoload.php');

    use GoogleCloudVisionVisionClient;

    $vision = new VisionClient([
        'projectId' => 'xxx',
        'keyFilePath' => 'xxx.json'
    ]);




    use GoogleCloudVisionV1ImageAnnotatorClient;


    function detect_text($path)
    {
        $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();
    }

    echo detect_text('read.png');

Installed the SDK and PHP Package and I'm getting error 500 no matter what I do!

How can I get this running?

This is the error I get:

[01-Feb-2020 19:09:48 UTC] PHP Warning:  file_exists(): open_basedir restriction in effect. File(C:Windowssystem32configsystemprofileAppDataRoaminggcloud/application_default_credentials.json) is not within the allowed path(s): (C:/Inetpub/vhosts/xxxxxxx.com;C:WindowsTemp) in C:Inetpubvhostsxxxxxxx.comvendorgoogleauthsrcCredentialsLoader.php on line 100
[01-Feb-2020 19:09:50 UTC] PHP Fatal error:  Uncaught DomainException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in C:Inetpubvhostsxxxxxxx.comvendorgoogleauthsrcApplicationDefaultCredentials.php:168
Stack trace:
#0 C:Inetpubvhostsxxxxxxx.comvendorgooglegaxsrcCredentialsWrapper.php(197): GoogleAuthApplicationDefaultCredentials::getCredentials(Array, Object(GoogleAuthHttpHandlerGuzzle6HttpHandler), NULL, NULL)
#1 C:Inetpubvhostsxxxxxxx.comvendorgooglegaxsrcCredentialsWrapper.php(114): GoogleApiCoreCredentialsWrapper::buildApplicationDefaultCredentials(Array, Object(GoogleAuthHttpHandlerGuzzle6HttpHandler))
#2 C:Inetpubvhostsxxxxxxx.comvendorgooglegaxsrcGapicClientTrait.php(339): GoogleApiCoreCredentialsWrapper::build(Array)
#3 C:Inetpubvhostsxxxxxxx.comvendorgooglegaxsrcGapicClientTrait.php(321): GoogleCloudVisionV1GapicImageAnnotatorGapicClient->createCredentialsWrapper(NULL, in C:Inetpubvhostsxxxxxxx.comvendorgooglegaxsrcCredentialsWrapper.php on line 200

I have done everything exactly how their documentation said to: https://cloud.google.com/vision/docs/setup what am I suppose to do now?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
428 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...