Skip to content

Commit

Permalink
samples: migrate code from googleapis/java-vision (#7428)
Browse files Browse the repository at this point in the history
### Migrating samples from [googleapis/java-vision](https://togithub.com/googleapis/java-vision/tree/main/samples) into [java-docs-samples/vision](https://togithub.com/GoogleCloudPlatform/java-docs-samples)
---

- samples: Vision v1p1beta1 samples (#951)
- samples: IoT MQTT Tests (#966)
- samples: Generalized testDetextWebEntitiesIncludeGeoResults. (#976)
- samples: Update of Flexible folder and the top-level parent pom.  (#1004)
- samples: Fix tests due to backend changes (#1081)
- samples: Add vision ocr for pdf/tiff (#1078)
- samples: Update vision dependency version and fix test. (#1099)
- samples: Vision beta samples (#1154)
- samples: Vision region tag update (#1182)
- samples: Udpate Beta Vision samples to use beta tags (#1184)
- samples: Remove unused Vision samples and region tags (#1208)
- samples: Beta feature : Vision : PDF/TIFF/GIF document feature detection (#1349)
- samples: vision: address flakes due to collisions. (#1458)
- samples: Fix failing beta tets (#1592)
- feat: make repo releasable, add parent/bom (#1)
- chore: update common templates, regenerate tests (#20)
- chore(regen): update license year for generated files (#48)
- samples: fix generated samples directory (#70)
- samples: add scaffold (#84)
- chore(deps): update dependency com.google.cloud:libraries-bom to v4.3.0 (#88)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.13 (#92)
- samples: docs: update tests that are failing or not cleaning up resources
- samples: update shared config (#2443)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.14 (#96)
- chore(deps): update dependency com.google.cloud:libraries-bom to v4.4.0 (#97)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.15 (#100)
- chore(deps): update dependency com.google.cloud:libraries-bom to v4.4.1 (#101)
- chore(deps): update dependency com.google.cloud:libraries-bom to v5 (#110)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.16 (#115)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.17 (#121)
- chore(deps): update dependency com.google.cloud:libraries-bom to v5.2.0 (#125)
- chore(deps): update dependency com.google.cloud:libraries-bom to v5.3.0 (#129)
- chore(deps): update dependency com.google.cloud:libraries-bom to v5.4.0 (#139)
- chore(deps): update dependency com.google.cloud:libraries-bom to v5.6.0 (#149)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.18 (#155)
- chore(deps): update dependency com.google.cloud:libraries-bom to v5.7.0 (#157)
- chore(deps): update dependency com.google.cloud:libraries-bom to v6 (#162)
- chore(deps): update dependency com.google.cloud:libraries-bom to v7 (#168)
- chore(deps): update dependency com.google.cloud:libraries-bom to v7.0.1 (#176)
- chore(deps): update dependency com.google.cloud:libraries-bom to v7.0.2 (#178)
- chore(deps): update dependency com.google.cloud:libraries-bom to v8 (#179)
- chore(deps): update dependency com.google.cloud:libraries-bom to v8.1.0 (#188)
- samples: Cloud Client Vision How-to snippets (#485)
- samples: Adds GCS snippets, was blocked by https://goo.gl/uWgYhQ
- samples: Fixes checkstyle, 3P libs before java libs
- samples: Updates vision to the latest library (#548)
- samples: Updates snippets so the API client is created in examples (#572)
- samples: Infer project from env
- samples: Vision speech upgrade (#641)
- samples: Changes http test to point to better hosting.
- samples: Use Cloud Storage bucket for web URI test
- samples: Style nit
- samples: Change test to public GCS bucket.
- samples: Change test to environment variable.
- samples: updating to latest google-cloud-* dependencies (#723)
- samples: Closes image annotator client.
- samples: Uses try with resource to ensure client gets closed.
- samples: upgrade Guava (#802)
- samples: Don't check for location (#809)
- samples: Vision v1p1beta1 samples (#951)
- samples: Update vision folder. (#999)
- samples: Update vision/beta web detection samples to v1 (#1016)
- samples: Fix tests for backend changes (#1082)
- samples: Update vision dependency version and fix test. (#1099)
- samples: Update OCR sample from beta to ga (#1123)
- samples: Vision region tag update (#1182)
- samples: Vision GA - library update (#1213)
- samples: vision: address changes in vision annotations. (#1326)
- samples: vision: address flakes due to collisions. (#1458)
- samples: Fix failing tests (#1591)
- samples: Add vision ocr set endpoint snippets (#1748)
- samples: vision: change flaky tests to mocks (#2254)
- samples: vision: move samples out of branch (#2298)
- samples: vision: move samples out of branch and add clarifying comments (#2297)
- samples: fix: region tag (#2312)
- samples: vision: makes tests more generic (#2475)
- samples: update shared config (#2443)
- samples: chore: added comment on try/catch block (#2980)
- samples: chore: splitting sample into single files (#3083)
- samples: fix test dependencies
- samples: fix resources
- samples: Vision Product Search (#1161)
- samples: Vision region tag update (#1182)
- samples: Adding the Product Search tests. (#1195)
- samples: Added the Product Search tests and the src file updates (#1196)
- samples: Vision Product Search - GA (#1257)
- samples: Pdt search updates (#1473)
- samples: Purge Products (#1569)
- samples: vision: update product search tests (#2378)
- samples: vision: use uuid for product search tests
- samples: Update ImportProductSetsIT.java
- samples: bump timeouts
- samples: update shared config (#2443)
- samples: fix resources and dependencies
- samples: fix resources
- chore(deps): update dependency com.google.cloud:libraries-bom to v9 (#207)
- chore(deps): update dependency com.google.cloud:libraries-bom to v9.1.0
- chore(deps): update dependency com.google.cloud:libraries-bom to v10
- chore(deps): update dependency com.google.cloud:libraries-bom to v11
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.21 (#244)
- chore(deps): update dependency com.google.cloud:libraries-bom to v12 (#249)
- test(deps): update dependency junit:junit to v4.13.1
- chore(deps): update dependency com.google.cloud:libraries-bom to v12.1.0 (#262)
- chore(deps): update dependency com.google.cloud:libraries-bom to v13 (#272)
- test(deps): update dependency com.google.truth:truth to v1.1 (#274)
- chore(deps): update dependency com.google.cloud:libraries-bom to v13.2.0 (#284)
- chore(deps): update dependency com.google.cloud:libraries-bom to v13.3.0 (#287)
- chore(deps): update dependency com.google.cloud:libraries-bom to v13.4.0 (#297)
- chore: moving the rest of the vision samples (#291)
- samples(deps): update spring.version to v2.3.5.release (#305)
- chore(deps): update dependency com.google.cloud:libraries-bom to v14 (#307)
- chore(deps): update dependency com.google.cloud:libraries-bom to v15 (#310)
- chore(deps): update dependency com.google.cloud:libraries-bom to v16 (#326)
- chore(deps): update dependency com.google.cloud:libraries-bom to v16.2.0 (#357)
- chore(deps): update dependency com.google.cloud:libraries-bom to v16.2.1 (#362)
- samples(deps): update dependency org.springframework.cloud:spring-cloud-gcp-dependencies to v1.2.6.release (#313)
- samples(deps): update spring.version to v2.4.1 (#320)
- samples(deps): update spring.version to v2.4.2 (#374)
- chore(deps): update dependency com.google.cloud:libraries-bom to v16.4.0 (#373)
- test(deps): update dependency junit:junit to v4.13.2 (#397)
- test(samples): prevent failure in nightly run by adding retry (#392)
- chore(deps): update dependency com.google.cloud:libraries-bom to v17 (#411)
- samples(deps): update dependency com.google.cloud:google-cloud-core to v1.94.1 (#405)
- samples(deps): update spring.version to v2.4.3 (#402)
- samples(deps): update dependency org.springframework.cloud:spring-cloud-gcp-dependencies to v1.2.7.release (#395)
- chore(deps): update dependency com.google.cloud:libraries-bom to v18 (#414)
- deps: update dependency com.google.cloud:google-cloud-core to v1.94.2 (#423)
- chore(deps): update dependency com.google.cloud:libraries-bom to v18.1.0 (#427)
- chore(deps): update dependency com.google.cloud:libraries-bom to v19 (#431)
- deps: update dependency com.google.cloud:google-cloud-core to v1.94.3 (#428)
- chore(deps): update dependency com.google.cloud:libraries-bom to v19.1.0 (#445)
- chore(deps): update dependency com.google.cloud:libraries-bom to v19.2.1 (#447)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.22 (#454)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20 (#463)
- deps: update dependency net.sourceforge.argparse4j:argparse4j to v0.9.0 (#455)
- deps: update dependency com.google.cloud:google-cloud-core to v1.94.7 (#441)
- deps: update spring.version to v2.4.4 (#448)
- deps: update spring.version to v2.4.5 (#474)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.1.0 (#475)
- chore: service throttles on public URLs & its known issue. (#477)
- deps: update dependency com.google.cloud:google-cloud-core to v1.94.8 (#482)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.2.0 (#487)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.3.0 (#500)
- test(deps): update dependency com.google.truth:truth to v1.1.2 (#498)
- deps: update dependency org.springframework.cloud:spring-cloud-gcp-dependencies to v1.2.8.release (#497)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.4.0 (#509)
- test(deps): update dependency com.google.truth:truth to v1.1.3 (#520)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.5.0 (#519)
- deps: update spring.version to v2.5.0 (#516)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.6.0 (#537)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.23 (#536)
- deps: update dependency com.google.cloud:google-cloud-core to v1.95.1 (#533)
- deps: update dependency com.google.cloud:google-cloud-core to v1.95.2 (#542)
- deps: update spring.version to v2.5.1 (#544)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.7.0 (#564)
- deps: update spring.version to v2.5.2 (#566)
- deps: update dependency com.google.cloud:google-cloud-core to v1.95.4 (#563)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.8.0 (#575)
- chore(deps): update dependency com.google.cloud:libraries-bom to v20.9.0 (#586)
- deps: update dependency com.google.cloud:google-cloud-core to v2 (#599)
- deps: update dependency org.apache.commons:commons-csv to v1.9.0 (#598)
- deps: update dependency com.google.cloud:google-cloud-core to v2.0.3 (#611)
- deps: update dependency com.google.cloud:google-cloud-core to v2.0.5 (#614)
- deps: update spring.version to v2.5.4 (#581)
- chore(deps): update dependency com.google.cloud:libraries-bom to v21 (#619)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.0 (#634)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.1 (#641)
- chore(deps): update dependency com.google.cloud:libraries-bom to v22 (#650)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.2 (#652)
- chore(deps): update dependency com.google.cloud:libraries-bom to v23 (#668)
- chore: migrate to owlbot (#663)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.3 (#674)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.4 (#685)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.6 (#692)
- deps: update spring.version to v2.5.5 (#703)
- deps: update dependency com.google.cloud:google-cloud-core to v2.1.7 (#702)
- chore(deps): update dependency com.google.cloud:libraries-bom to v23.1.0 (#715)
- deps: update dependency com.google.cloud:google-cloud-core to v2.2.0 (#720)
- deps: update spring.version to v2.5.6 (#729)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24 (#733)
- deps: update dependency com.google.cloud:google-cloud-core to v2.3.0 (#744)
- deps: update dependency com.google.cloud:google-cloud-core to v2.3.1 (#746)
- deps: update spring.version to v2.6.0 (#749)
- deps: update dependency com.google.cloud:google-cloud-core to v2.3.2 (#756)
- deps: update dependency com.google.cloud:google-cloud-core to v2.3.3 (#758)
- deps: update dependency org.springframework.boot:spring-boot-starter-web to v2.6.1 (#751)
- chore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.2.0 (#755)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24.1.0 (#767)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24.1.1 (#769)
- deps: update dependency com.google.cloud:google-cloud-core to v2.3.4 (#772)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24.1.2 (#773)
- deps: update dependency com.google.cloud:google-cloud-core to v2.3.5 (#779)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24.2.0 (#788)
- deps: update spring.version to v2.6.3 (#768)
- deps: update dependency com.google.cloud:google-cloud-core to v2.4.0 (#797)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24.3.0 (#809)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.0 (#804)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.1 (#811)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.3 (#812)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.4 (#816)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.5 (#825)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.6 (#828)
- chore(deps): update dependency com.google.cloud:libraries-bom to v24.4.0 (#830)
- deps: update dependency org.springframework.boot:spring-boot-maven-plugin to v2.6.4 (#822)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.8 (#840)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.9 (#844)
- chore(deps): update dependency com.google.cloud:libraries-bom to v25 (#850)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.10 (#849)
- deps: update spring.version to v2.6.5 (#855)
- deps: update dependency com.google.cloud:google-cloud-core to v2.5.11 (#860)
- chore(deps): update dependency com.google.cloud:libraries-bom to v25.1.0 (#866)
- build(deps): bump spring-boot-starter-web in /samples/spring-framework (#867)
- deps: update dependency com.google.cloud:google-cloud-core to v2.6.1 (#878)
- deps: update spring.version to v2.6.7 (#888)
- chore(deps): update dependency com.google.cloud:libraries-bom to v25.2.0 (#891)
- chore(deps): update dependency com.google.cloud:libraries-bom to v25.3.0 (#905)
- deps: update spring.version to v2.7.0 (#908)
- deps: update dependency com.google.cloud:google-cloud-core to v2.7.1 (#906)
- chore(deps): update dependency com.google.cloud:libraries-bom to v25.4.0 (#917)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.0 (#920)
- deps: update spring.version to v2.7.1 (#925)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.1 (#931)
- chore(deps): update dependency com.google.cloud:libraries-bom to v26 (#945)
- deps: update spring.version to v2.7.2 (#951)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.6 (#955)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.7 (#958)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.8 (#960)
- chore(deps): update dependency com.google.cloud:libraries-bom to v26.1.0 (#970)
- deps: update spring.version to v2.7.3 (#974)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.9 (#973)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.10 (#977)
- chore(deps): update dependency com.google.cloud:libraries-bom to v26.1.1 (#978)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.11 (#980)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.12 (#984)
- chore(deps): update dependency com.google.cloud:libraries-bom to v26.1.2 (#990)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.13 (#992)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.14 (#993)
- deps: update spring.version to v2.7.4 (#994)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.18 (#995)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.19 (#1023)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.20 (#1025)
- chore(deps): update dependency com.google.cloud:libraries-bom to v26.1.3 (#1031)
- deps: update dependency com.google.cloud:google-cloud-core to v2.8.21 (#1034)

Fixes #issue

> It's a good idea to open an issue first for discussion.

- [ ] I have followed [Sample Format Guide](https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md)
- [ ] `pom.xml` parent set to latest `shared-configuration`
- [ ] Appropriate changes to README are included in PR
- [ ] API's need to be enabled to test (tell us)
- [ ] Environment Variables need to be set (ask us to set them)
- [ ] **Tests** pass:   `mvn clean verify` **required**
- [ ] **Lint**  passes: `mvn -P lint checkstyle:check` **required**
- [ ] **Static Analysis**:  `mvn -P lint clean compile pmd:cpd-check spotbugs:check` **advisory only**
- [ ] Please **merge** this PR for me once it is approved.
  • Loading branch information
Shabirmean authored and anguillanneuf committed Dec 5, 2022
1 parent 91877c9 commit 29117e9
Show file tree
Hide file tree
Showing 98 changed files with 7,879 additions and 0 deletions.
82 changes: 82 additions & 0 deletions vision/snippets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.vision</groupId>
<artifactId>vision-snippets</artifactId>
<packaging>jar</packaging>
<name>Google Cloud Vision Snippets</name>
<url>https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/vision</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.2.0</version>
</parent>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<!-- [START vision_install_with_bom] -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.1.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
</dependency>
<!-- [START_EXCLUDE] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>2.8.21</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
<!-- [END_EXCLUDE] -->
</dependencies>
<!-- [END vision_install_with_bom] -->
</project>
Binary file added vision/snippets/resources/city.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/face_no_surprise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/gcp-logos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/handwritten.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions vision/snippets/resources/indexed_product_sets.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"gs://java-docs-samples-testing/product-search/shoes_1.jpg","indexed_product_set_id_for_testing","indexed_product_id_for_testing_1","apparel","style=womens","0.1,0.1,0.9,0.1,0.9,0.9,0.1,0.9"
"gs://java-docs-samples-testing/product-search/shoes_2.jpg","indexed_product_set_id_for_testing","indexed_product_id_for_testing_2","apparel",,
Binary file added vision/snippets/resources/kafka.pdf
Binary file not shown.
Binary file added vision/snippets/resources/landmark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/logos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions vision/snippets/resources/product_sets.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"gs://java-docs-samples-testing/product-search/shoes_1.jpg","fake_product_set_id_for_testing","fake_product_id_for_testing_1","apparel","style=womens","0.1,0.1,0.9,0.1,0.9,0.9,0.1,0.9"
"gs://java-docs-samples-testing/product-search/shoes_2.jpg","fake_product_set_id_for_testing","fake_product_id_for_testing_2","apparel",,
Binary file added vision/snippets/resources/puppies.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/shoes_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/shoes_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/text.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/snippets/resources/wakeupcat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.vision;

// [START vision_async_batch_annotate_images_beta]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.Storage.BlobListOption;
import com.google.cloud.storage.StorageOptions;
import com.google.cloud.vision.v1p4beta1.AnnotateImageRequest;
import com.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesRequest;
import com.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesResponse;
import com.google.cloud.vision.v1p4beta1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1p4beta1.BatchAnnotateImagesResponse.Builder;
import com.google.cloud.vision.v1p4beta1.Feature;
import com.google.cloud.vision.v1p4beta1.Feature.Type;
import com.google.cloud.vision.v1p4beta1.GcsDestination;
import com.google.cloud.vision.v1p4beta1.Image;
import com.google.cloud.vision.v1p4beta1.ImageAnnotatorClient;
import com.google.cloud.vision.v1p4beta1.ImageSource;
import com.google.cloud.vision.v1p4beta1.OperationMetadata;
import com.google.cloud.vision.v1p4beta1.OutputConfig;
import com.google.protobuf.util.JsonFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AsyncBatchAnnotateImagesGcs {

// Performs asynchronous batch annotation of images on Google Cloud Storage
public static void asyncBatchAnnotateImagesGcs(String gcsSourcePath, String gcsDestinationPath)
throws Exception {
// String gcsSourcePath = "gs://YOUR_BUCKET_ID/path_to_your_data";
// String gcsDestinationPath = "gs://YOUR_BUCKET_ID/path_to_store_annotation";
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();

ImageSource imgSource = ImageSource.newBuilder().setImageUri(gcsSourcePath).build();

Image image = Image.newBuilder().setSource(imgSource).build();

// Set the GCS destination path for where to save the results.
GcsDestination gcsDestination =
GcsDestination.newBuilder().setUri(gcsDestinationPath).build();

// Create the configuration for the output with the batch size.
// The batch size sets how many pages should be grouped into each json output file.
OutputConfig outputConfig =
OutputConfig.newBuilder().setGcsDestination(gcsDestination).setBatchSize(2).build();

// Select the Features required by the vision API
Feature features =
Feature.newBuilder()
.setType(Type.LABEL_DETECTION)
.setType(Type.TEXT_DETECTION)
.setType(Type.IMAGE_PROPERTIES)
.build();

// Build the request
AnnotateImageRequest annotateImageRequest =
AnnotateImageRequest.newBuilder().setImage(image).addFeatures(features).build();

requests.add(annotateImageRequest);
AsyncBatchAnnotateImagesRequest request =
AsyncBatchAnnotateImagesRequest.newBuilder()
.addAllRequests(requests)
.setOutputConfig(outputConfig)
.build();

OperationFuture<AsyncBatchAnnotateImagesResponse, OperationMetadata> response =
client.asyncBatchAnnotateImagesAsync(request);
System.out.println("Waiting for the operation to finish.");

// we're not processing the response, since we'll be reading the output from GCS.
response.get(180, TimeUnit.SECONDS);

// Once the request has completed and the output has been
// written to GCS, we can list all the output files.
Storage storage = StorageOptions.getDefaultInstance().getService();

// Get the destination location from the gcsDestinationPath
Pattern pattern = Pattern.compile("gs://([^/]+)/(.+)");
Matcher matcher = pattern.matcher(gcsDestinationPath);

if (matcher.find()) {
String bucketName = matcher.group(1);
String prefix = matcher.group(2);

// Get the list of objects with the given prefix from the GCS bucket
Bucket bucket = storage.get(bucketName);
Page<Blob> pageList = bucket.list(BlobListOption.prefix(prefix));

Blob firstOutputFile = null;

// List objects with the given prefix.
System.out.println("Output files:");
for (Blob blob : pageList.iterateAll()) {
System.out.println(blob.getName());

// Process the first output file from GCS.
// Since we specified batch size = 2, the first response contains
// the first two image requests
if (firstOutputFile == null) {
firstOutputFile = blob;
}
}

// Get the contents of the file and convert the JSON contents to an
// BatchAnnotateImagesResponse
// object. If the Blob is small read all its content in one request
// (Note: the file is a .json file)
// Storage guide: https://cloud.google.com/storage/docs/downloading-objects
String jsonContents = new String(firstOutputFile.getContent());
Builder builder = BatchAnnotateImagesResponse.newBuilder();
JsonFormat.parser().merge(jsonContents, builder);

// Build the AnnotateFileResponse object
BatchAnnotateImagesResponse batchAnnotateImagesResponse = builder.build();

// Here we print the response for the first image
// The response contains more information:
// annotation/pages/blocks/paragraphs/words/symbols/colors
// including confidence score and bounding boxes
System.out.format("\nResponse: %s\n", batchAnnotateImagesResponse.getResponses(0));

} else {
System.out.println("No MATCH");
}
} catch (Exception e) {
System.out.println("Error during asyncBatchAnnotateImagesGcs: \n" + e.toString());
}
}
}

// [END vision_async_batch_annotate_images_beta]
Loading

0 comments on commit 29117e9

Please sign in to comment.