use of com.google.cloud.vision.v1p3beta1.AnnotateImageRequest in project java-vision by googleapis.
the class ITSystemTest method detectWebEntitiesIncludeGeoResultsGcsTest.
@Test
public void detectWebEntitiesIncludeGeoResultsGcsTest() {
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(SAMPLE_BUCKET + "landmark/pofa.jpg").build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).setMaxResults(MAX_RESULTS).build();
WebDetectionParams webDetectionParams = WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
ImageContext imageContext = ImageContext.newBuilder().setWebDetectionParams(webDetectionParams).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImageContext(imageContext).setImage(img).build();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request));
List<AnnotateImageResponse> responses = response.getResponsesList();
List<String> actual = new ArrayList<>();
System.out.println("WebEntitiesGeo SIZE");
System.out.println(actual.size());
for (AnnotateImageResponse imgResponse : responses) {
for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) {
actual.add(entity.getDescription());
}
}
assertThat(actual).contains("The Palace Of Fine Arts");
}
use of com.google.cloud.vision.v1p3beta1.AnnotateImageRequest in project java-vision by googleapis.
the class ITSystemTest method detectLandmarksUrlTest.
@Test
public void detectLandmarksUrlTest() throws Exception {
ImageSource imgSource = ImageSource.newBuilder().setImageUri(SAMPLE_URI + "landmark/pofa.jpg").build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.LANDMARK_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
List<String> actual = new ArrayList<>();
int tryCount = 0;
int maxTries = 3;
while (tryCount < maxTries) {
try {
actual = addResponsesToList(request);
break;
} catch (StatusRuntimeException ex) {
tryCount++;
System.out.println("retrying due to request throttling or DOS prevention...");
TimeUnit.SECONDS.sleep(30);
}
}
assertThat(actual).contains("Palace of Fine Arts");
}
Aggregations