From f7b1aba047907e90ba67fa0034bc22a05be5ca02 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Thu, 8 Nov 2018 16:31:28 -0800 Subject: [PATCH] Add a helper for product search (#1414) --- Vision/src/V1/ImageAnnotatorClient.php | 35 +++++++++++++++++++ .../Snippet/V1/ImageAnnotatorClientTest.php | 1 + .../V1/ImageAnnotatorClientExtensionTest.php | 1 + 3 files changed, 37 insertions(+) diff --git a/Vision/src/V1/ImageAnnotatorClient.php b/Vision/src/V1/ImageAnnotatorClient.php index ae9ad3ad6f72..45fa0f6dba0a 100644 --- a/Vision/src/V1/ImageAnnotatorClient.php +++ b/Vision/src/V1/ImageAnnotatorClient.php @@ -510,6 +510,41 @@ public function objectLocalization($image, $optionalArgs = []) ); } + /** + * Run product search for an image. + * + * Example: + * ``` + * $imageContent = file_get_contents('path/to/image.jpg'); + * $response = $imageAnnotatorClient->productSearch($imageContent); + * ``` + * + * @param resource|string|Image $image The image to be processed. + * @param array $optionalArgs { + * Configuration Options. + * + * @type ImageContext $imageContext Additional context that may accompany the image. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array + * of retry settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return AnnotateImageResponse + * + * @throws ApiException if the remote call fails + * @experimental + */ + public function productSearch($image, $optionalArgs = []) + { + return $this->annotateSingleFeature( + $image, + Type::PRODUCT_SEARCH, + $optionalArgs + ); + } + /** * @param Image $image * @param Feature|int $featureType diff --git a/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php b/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php index 1a714c6aa27f..378e4ac696bb 100644 --- a/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php +++ b/Vision/tests/Snippet/V1/ImageAnnotatorClientTest.php @@ -135,6 +135,7 @@ public function detectionMethodSnippetDataProvider() ['cropHintsDetection'], ['webDetection'], ['objectLocalization'], + ['productSearch'], ]; } diff --git a/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php b/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php index e732b4d122f3..10f1dc47176a 100644 --- a/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php +++ b/Vision/tests/Unit/V1/ImageAnnotatorClientExtensionTest.php @@ -200,6 +200,7 @@ public function detectionMethodDataProvider() ['cropHintsDetection', Feature_Type::CROP_HINTS], ['webDetection', Feature_Type::WEB_DETECTION], ['objectLocalization', Feature_Type::OBJECT_LOCALIZATION], + ['productSearch', Feature_Type::PRODUCT_SEARCH], ]; $data = []; foreach ($items as $item) {