-
Notifications
You must be signed in to change notification settings - Fork 2.9k
chore: splitting sample into single files #3083
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
903 changes: 4 additions & 899 deletions
903
vision/cloud-client/src/main/java/com/example/vision/Detect.java
Large diffs are not rendered by default.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHints.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2017 Google Inc. | ||
* | ||
* 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.snippets; | ||
|
||
// [START vision_crop_hint_detection] | ||
|
||
import com.google.cloud.vision.v1.AnnotateImageRequest; | ||
import com.google.cloud.vision.v1.AnnotateImageResponse; | ||
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; | ||
import com.google.cloud.vision.v1.CropHint; | ||
import com.google.cloud.vision.v1.CropHintsAnnotation; | ||
import com.google.cloud.vision.v1.Feature; | ||
import com.google.cloud.vision.v1.Image; | ||
import com.google.cloud.vision.v1.ImageAnnotatorClient; | ||
import com.google.protobuf.ByteString; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DetectCropHints { | ||
public static void detectCropHints() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String filePath = "path/to/your/image/file.jpg"; | ||
detectCropHints(filePath); | ||
} | ||
|
||
// Suggests a region to crop to for a local file. | ||
public static void detectCropHints(String filePath) throws IOException { | ||
List<AnnotateImageRequest> requests = new ArrayList<>(); | ||
|
||
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath)); | ||
|
||
Image img = Image.newBuilder().setContent(imgBytes).build(); | ||
Feature feat = Feature.newBuilder().setType(Feature.Type.CROP_HINTS).build(); | ||
AnnotateImageRequest request = | ||
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); | ||
requests.add(request); | ||
|
||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { | ||
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); | ||
List<AnnotateImageResponse> responses = response.getResponsesList(); | ||
|
||
for (AnnotateImageResponse res : responses) { | ||
if (res.hasError()) { | ||
System.out.format("Error: %s%n", res.getError().getMessage()); | ||
return; | ||
} | ||
|
||
// For full list of available annotations, see http://g.co/cloud/vision/docs | ||
CropHintsAnnotation annotation = res.getCropHintsAnnotation(); | ||
for (CropHint hint : annotation.getCropHintsList()) { | ||
System.out.println(hint.getBoundingPoly()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// [END vision_crop_hint_detection] |
75 changes: 75 additions & 0 deletions
75
vision/cloud-client/src/main/java/com/example/vision/snippets/DetectCropHintsGcs.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2017 Google Inc. | ||
lesv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* 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.snippets; | ||
|
||
// [START vision_crop_hint_detection_gcs] | ||
|
||
import com.google.cloud.vision.v1.AnnotateImageRequest; | ||
import com.google.cloud.vision.v1.AnnotateImageResponse; | ||
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; | ||
import com.google.cloud.vision.v1.CropHint; | ||
import com.google.cloud.vision.v1.CropHintsAnnotation; | ||
import com.google.cloud.vision.v1.Feature; | ||
import com.google.cloud.vision.v1.Image; | ||
import com.google.cloud.vision.v1.ImageAnnotatorClient; | ||
import com.google.cloud.vision.v1.ImageSource; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DetectCropHintsGcs { | ||
|
||
public static void detectCropHintsGcs() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg"; | ||
detectCropHintsGcs(filePath); | ||
} | ||
|
||
// Suggests a region to crop to for a remote file on Google Cloud Storage. | ||
public static void detectCropHintsGcs(String gcsPath) throws IOException { | ||
List<AnnotateImageRequest> requests = new ArrayList<>(); | ||
|
||
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build(); | ||
Image img = Image.newBuilder().setSource(imgSource).build(); | ||
Feature feat = Feature.newBuilder().setType(Feature.Type.CROP_HINTS).build(); | ||
AnnotateImageRequest request = | ||
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); | ||
requests.add(request); | ||
|
||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { | ||
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); | ||
List<AnnotateImageResponse> responses = response.getResponsesList(); | ||
|
||
for (AnnotateImageResponse res : responses) { | ||
if (res.hasError()) { | ||
System.out.format("Error: %s%n", res.getError().getMessage()); | ||
return; | ||
} | ||
|
||
// For full list of available annotations, see http://g.co/cloud/vision/docs | ||
CropHintsAnnotation annotation = res.getCropHintsAnnotation(); | ||
for (CropHint hint : annotation.getCropHintsList()) { | ||
System.out.println(hint.getBoundingPoly()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// [END vision_crop_hint_detection_gcs] |
75 changes: 75 additions & 0 deletions
75
vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarks.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2017 Google Inc. | ||
* | ||
* 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.snippets; | ||
|
||
// [START vision_landmark_detection] | ||
|
||
import com.google.cloud.vision.v1.AnnotateImageRequest; | ||
import com.google.cloud.vision.v1.AnnotateImageResponse; | ||
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; | ||
import com.google.cloud.vision.v1.EntityAnnotation; | ||
import com.google.cloud.vision.v1.Feature; | ||
import com.google.cloud.vision.v1.Image; | ||
import com.google.cloud.vision.v1.ImageAnnotatorClient; | ||
import com.google.cloud.vision.v1.LocationInfo; | ||
import com.google.protobuf.ByteString; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DetectLandmarks { | ||
public static void detectLandmarks() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String filePath = "path/to/your/image/file.jpg"; | ||
detectLandmarks(filePath); | ||
} | ||
|
||
// Detects landmarks in the specified local image. | ||
public static void detectLandmarks(String filePath) throws IOException { | ||
List<AnnotateImageRequest> requests = new ArrayList<>(); | ||
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath)); | ||
|
||
Image img = Image.newBuilder().setContent(imgBytes).build(); | ||
Feature feat = Feature.newBuilder().setType(Feature.Type.LANDMARK_DETECTION).build(); | ||
AnnotateImageRequest request = | ||
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); | ||
requests.add(request); | ||
|
||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { | ||
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); | ||
List<AnnotateImageResponse> responses = response.getResponsesList(); | ||
|
||
for (AnnotateImageResponse res : responses) { | ||
if (res.hasError()) { | ||
System.out.format("Error: %s%n", res.getError().getMessage()); | ||
return; | ||
} | ||
|
||
// For full list of available annotations, see http://g.co/cloud/vision/docs | ||
for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) { | ||
LocationInfo info = annotation.getLocationsList().listIterator().next(); | ||
System.out.format("Landmark: %s%n %s%n", annotation.getDescription(), info.getLatLng()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// [END vision_landmark_detection] |
75 changes: 75 additions & 0 deletions
75
vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksGcs.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2017 Google Inc. | ||
* | ||
* 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.snippets; | ||
|
||
// [START vision_landmark_detection_gcs] | ||
|
||
import com.google.cloud.vision.v1.AnnotateImageRequest; | ||
import com.google.cloud.vision.v1.AnnotateImageResponse; | ||
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; | ||
import com.google.cloud.vision.v1.EntityAnnotation; | ||
import com.google.cloud.vision.v1.Feature; | ||
import com.google.cloud.vision.v1.Image; | ||
import com.google.cloud.vision.v1.ImageAnnotatorClient; | ||
import com.google.cloud.vision.v1.ImageSource; | ||
import com.google.cloud.vision.v1.LocationInfo; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DetectLandmarksGcs { | ||
|
||
public static void detectLandmarksGcs() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg"; | ||
detectLandmarksGcs(filePath); | ||
} | ||
|
||
// Detects landmarks in the specified remote image on Google Cloud Storage. | ||
public static void detectLandmarksGcs(String gcsPath) throws IOException { | ||
List<AnnotateImageRequest> requests = new ArrayList<>(); | ||
|
||
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build(); | ||
Image img = Image.newBuilder().setSource(imgSource).build(); | ||
Feature feat = Feature.newBuilder().setType(Feature.Type.LANDMARK_DETECTION).build(); | ||
AnnotateImageRequest request = | ||
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); | ||
requests.add(request); | ||
|
||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { | ||
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); | ||
List<AnnotateImageResponse> responses = response.getResponsesList(); | ||
|
||
for (AnnotateImageResponse res : responses) { | ||
if (res.hasError()) { | ||
System.out.format("Error: %s%n", res.getError().getMessage()); | ||
return; | ||
} | ||
|
||
// For full list of available annotations, see http://g.co/cloud/vision/docs | ||
for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) { | ||
LocationInfo info = annotation.getLocationsList().listIterator().next(); | ||
System.out.format("Landmark: %s%n %s%n", annotation.getDescription(), info.getLatLng()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// [END vision_landmark_detection_gcs] |
72 changes: 72 additions & 0 deletions
72
vision/cloud-client/src/main/java/com/example/vision/snippets/DetectLandmarksUrl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2017 Google Inc. | ||
* | ||
* 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.snippets; | ||
|
||
import com.google.cloud.vision.v1.AnnotateImageRequest; | ||
import com.google.cloud.vision.v1.AnnotateImageResponse; | ||
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; | ||
import com.google.cloud.vision.v1.EntityAnnotation; | ||
import com.google.cloud.vision.v1.Feature; | ||
import com.google.cloud.vision.v1.Image; | ||
import com.google.cloud.vision.v1.ImageAnnotatorClient; | ||
import com.google.cloud.vision.v1.ImageSource; | ||
import com.google.cloud.vision.v1.LocationInfo; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DetectLandmarksUrl { | ||
|
||
public static void detectLandmarksUrl() throws IOException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String filePath = "gs://your-gcs-bucket/path/to/image/file.jpg"; | ||
detectLandmarksUrl(filePath); | ||
} | ||
|
||
// Detects landmarks in the specified URI. | ||
public static void detectLandmarksUrl(String uri) throws IOException { | ||
List<AnnotateImageRequest> requests = new ArrayList<>(); | ||
|
||
ImageSource imgSource = ImageSource.newBuilder().setImageUri(uri).build(); | ||
Image img = Image.newBuilder().setSource(imgSource).build(); | ||
Feature feat = Feature.newBuilder().setType(Feature.Type.LANDMARK_DETECTION).build(); | ||
AnnotateImageRequest request = | ||
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); | ||
requests.add(request); | ||
|
||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { | ||
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); | ||
List<AnnotateImageResponse> responses = response.getResponsesList(); | ||
|
||
for (AnnotateImageResponse res : responses) { | ||
if (res.hasError()) { | ||
System.out.format("Error: %s%n", res.getError().getMessage()); | ||
return; | ||
} | ||
|
||
// For full list of available annotations, see http://g.co/cloud/vision/docs | ||
for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) { | ||
LocationInfo info = annotation.getLocationsList().listIterator().next(); | ||
System.out.format("Landmark: %s%n %s%n", annotation.getDescription(), info.getLatLng()); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.