jordikroon / Php-Google-Vision-Api

Google Vision Api for PHP (https://cloud.google.com/vision/)
https://twitter.com/jordi_kr
MIT License
61 stars 22 forks source link

TEXT_DETECTION, DOCUMENT_TEXT_DETECTION display error #38

Open ifwelove opened 4 years ago

ifwelove commented 4 years ago

Symfony\Component\Debug\Exception\FatalThrowableError Argument 1 passed to Vision\Annotation\Word::__construct() must be an instance of Vision\Annotation\TextProperty, null given, called in /project/vendor/jordikroon/google-vision/src/Hydrator/Strategy/WordsStrategy.php on line 82

$apiKey = 'test';
$vision = new \Vision\Vision(
           $apiKey,
            [
                new \Vision\Feature(\Vision\Feature::TEXT_DETECTION, 100)
            ]
);
$imagePath = 'https://img.ali-img.net/img.alicdn.com/imgextra/i1/2243067373/O1CN01eE61ag24KskpsXLPX_!!2243067373.jpg_v_600.jpg';
$response = $vision->request(
            new \Vision\Request\Image\RemoteImage($imagePath)
);
dd($response);

public function hydrate($value)
    {
        $wordEntities = [];

        foreach ($value as $wordEntityInfo) {
            $textProperty = isset($wordEntityInfo['property'])
                ? $this->textPropertyStrategy->hydrate($wordEntityInfo['property'])
                : null;

            $boundingBox = isset($wordEntityInfo['boundingBox'])
                 ? $this->boundingPolyStrategy->hydrate($wordEntityInfo['boundingBox'])
                 : null;

            $symbols = isset($wordEntityInfo['symbols'])
                 ? $this->symbolsStrategy->hydrate($wordEntityInfo['symbols'])
                 : null;
            // $textProperty is null, Cause an error
            $wordEntities[] = new Word(
                $textProperty,
                $boundingBox,
                $symbols
            );
        }

        return $wordEntities;
    }
natelloyd commented 4 years ago

Also experiencing this on 1.8.0 and after upgrading to 1.8.2. Unfortunately not time to debug it much right now.

stephanrossi commented 4 years ago

There is a way to get it back to work again ?

jericosdelacruz commented 4 years ago

In the Word Class Constructor, do this:

public function __construct(TextProperty $property = null, BoundingPoly $boundingBox, array $symbols)