Php-Google-Vision-Api
Php-Google-Vision-Api copied to clipboard
TEXT_DETECTION, DOCUMENT_TEXT_DETECTION display error
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;
}
Also experiencing this on 1.8.0 and after upgrading to 1.8.2. Unfortunately not time to debug it much right now.
There is a way to get it back to work again ?
In the Word Class Constructor, do this:
public function __construct(TextProperty $property = null, BoundingPoly $boundingBox, array $symbols)