Skip to content

Conversation

@ryanmats
Copy link
Contributor

No description provided.

@ryanmats ryanmats requested a review from bshaffer July 25, 2017 03:20
$boundingPoly = $hint->boundingPoly();
$vertices = $boundingPoly['vertices'];
foreach ((array) $vertices as $vertice) {
if (!isset($vertice['x'])) $vertice['x'] = 0;
Copy link
Contributor Author

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?

Copy link
Contributor

@bshaffer bshaffer Jul 27, 2017

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.

Copy link
Contributor

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.

@ryanmats ryanmats changed the title First draft of crop hints Code samples for Vision 1.1 features Jul 27, 2017
Copy link
Contributor

@bshaffer bshaffer left a 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;
Copy link
Contributor

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'];
Copy link
Contributor

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'];

Copy link
Contributor Author

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'];
}
Copy link
Contributor

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.

Copy link
Contributor Author

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'];
}
}
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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']);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@ryanmats
Copy link
Contributor Author

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.

@bshaffer
Copy link
Contributor

Fixed the code styles error, so hopefully the tests will pass! If so this is LGTM.

@ryanmats ryanmats merged commit 4cb454c into master Jul 31, 2017
@bshaffer bshaffer deleted the vision-1.1-features branch August 1, 2017 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants