-
Notifications
You must be signed in to change notification settings - Fork 1k
Code samples for Vision 1.1 features #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| $boundingPoly = $hint->boundingPoly(); | ||
| $vertices = $boundingPoly['vertices']; | ||
| foreach ((array) $vertices as $vertice) { | ||
| if (!isset($vertice['x'])) $vertice['x'] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bshaffer It seems like I need this check here, otherwise I get an error if one of the hints has a 0-coordinate for x or y: 'Undefined index: x in /usr/local/google/home/ryanmats/php-docs-samples/vision/api/src/snippets/detect_crop_hints.php on line 38'.
However, it looks like none of the other code samples (https://cloud.google.com/vision/docs/detecting-crop-hints) require this check. Am I doing something wrong with the PHP syntax, or is our client library different from the others with regard to 0-coordinates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be an issue with the client libraries, i.e. the API is coming back with values and the library isn't propagating them through. However, I've seen this with other APIs where fields were missing in the API requests.
Something you could do is try making a REST request to the Vision API and see if the proper values are coming back. If they are, then it's most likely an issue with the client library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While worth looking into (because this is a bit hackish), this solution is ok for now.
bshaffer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just some minor output changes. Also, copy the existing tests to make sure we have coverage for the new methods.
Additionally, you can check out how we've done spanner samples and combined the quickstart directory with the api directory. Ideally, I would like to do this for all our samples, as this will be more straightforward for our end users. Essentially it means we remove all *Command.php classes and declare them inline in vision.php.
| $boundingPoly = $hint->boundingPoly(); | ||
| $vertices = $boundingPoly['vertices']; | ||
| foreach ((array) $vertices as $vertice) { | ||
| if (!isset($vertice['x'])) $vertice['x'] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While worth looking into (because this is a bit hackish), this solution is ok for now.
| foreach ($block['paragraphs'] as $paragraph) { | ||
| foreach ($paragraph['words'] as $word) { | ||
| foreach ($word['symbols'] as $symbol) { | ||
| $block_text = $block_text . $symbol['text']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be $block_text .= $symbol['text'];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| foreach ($paragraph['words'] as $word) { | ||
| foreach ($word['symbols'] as $symbol) { | ||
| $block_text = $block_text . $symbol['text']; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add $block_text .= ' '; so there is a space between words.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| foreach ($word['symbols'] as $symbol) { | ||
| $block_text = $block_text . $symbol['text']; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add $block_text .= "\n"; so there is a newline between paragraphs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| print('Block text: ' . $block_text . PHP_EOL); | ||
| print('Block bounds:' . PHP_EOL); | ||
| foreach ($block['boundingBox']['vertices'] as $vertice) { | ||
| print('X: ' . $vertice['x'] . ' Y: ' . $vertice['y'] . PHP_EOL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would look cleaner as
printf('X: %s Y: %s' . PHP_EOL, $vertice['x'], $vertice['y']);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…printing style, added tests
|
All the necessary samples / tests are now here. I still need to refactor the *Command.php classes and combine the api and quickstart directories - I'll do that next. |
|
Fixed the code styles error, so hopefully the tests will pass! If so this is LGTM. |
No description provided.