Search code examples
phpgoogle-apigoogle-cloud-platformgoogle-vision

Implement latest Google Cloud Vision Api Text/Logo Recognition update - LabelDetectionConfig - from Sept 28, 2018?


Anyone know how to set LabelDetectionConfig in Google Cloud Vision api for PHP?

Apparently there is new functionality released, described here: https://cloud.google.com/vision/docs/release-notes

Improved detection models are now available for the following features:

Logo Detection Text Detection (OCR) Specify "builtin/latest" in the LabelDetectionConfig field to use the new models.

We'll support both the current model and the new model the next 90 days. After 90 days the current detection models will be deprecated and only the new detection models will be used for all logo and text (OCR) detection requests.

This is what my code looks like now:

$vision = new VisionClient([
   'projectId' => XXXX
]);
$contents = get_contents($url);
$image = $vision->image($contents, ['LOGO_DETECTION']);
$result = $vision->annotate($image);

Solution

  • According to this documentation, this parameter is set in the "Feature" object, in the "model" field, and not as indicated in the Vision API release notes (LabelDetectionConfig). Taking a look at the PHP client, which I assume you are using, it allows you set a "$features" array, therefore, you can set this array by using the "model" parameter with the "builtin/latest" value.