use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.
the class ITSystemTest method detectLocalizedObjectsTest.
@Test
public void detectLocalizedObjectsTest() throws IOException {
List<AnnotateImageResponse> responses = getResponsesList("puppies.jpg", Type.OBJECT_LOCALIZATION, false);
List<String> actual = new ArrayList<>();
for (AnnotateImageResponse res : responses) {
for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) {
actual.add(entity.getName());
}
}
assertThat(actual).contains("Dog");
}
use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.
the class ITSystemTest method detectWebEntitiesTest.
@Test
public void detectWebEntitiesTest() throws IOException {
List<AnnotateImageResponse> responses = getResponsesList("city.jpg", Type.WEB_DETECTION, false);
List<String> actual = new ArrayList<>();
for (AnnotateImageResponse imgResponse : responses) {
for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) {
actual.add(entity.getDescription());
}
}
assertThat(actual).contains("Skyscraper");
}
use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.
the class ITSystemTest method detectSafeSearchGcsTest.
@Test
public void detectSafeSearchGcsTest() throws IOException {
List<AnnotateImageResponse> responses = getResponsesList("label/wakeupcat.jpg", Type.SAFE_SEARCH_DETECTION, true);
for (AnnotateImageResponse res : responses) {
SafeSearchAnnotation annotation = res.getSafeSearchAnnotation();
assertEquals(Likelihood.VERY_UNLIKELY, annotation.getAdult());
assertEquals(Likelihood.VERY_UNLIKELY, annotation.getRacy());
}
}
use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.
the class ITSystemTest method detectWebEntitiesIncludeGeoResultsTest.
@Test
public void detectWebEntitiesIncludeGeoResultsTest() throws IOException {
ByteString imgBytes = ByteString.readFrom(new FileInputStream(RESOURCES + "city.jpg"));
Image img = Image.newBuilder().setContent(imgBytes).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<>();
for (AnnotateImageResponse imgResponse : responses) {
for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) {
actual.add(entity.getDescription());
}
}
List<String> expectedResults = new ArrayList<>();
expectedResults.add("Electra Tower");
expectedResults.add("Metropolitan area");
assertThat(actual).containsAnyIn(expectedResults);
}
use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.
the class ITSystemTest method detectCropHintsGcsTest.
@Test
public void detectCropHintsGcsTest() throws IOException {
List<AnnotateImageResponse> responses = getResponsesList("label/wakeupcat.jpg", Type.CROP_HINTS, true);
List<Integer> actual = new ArrayList<>();
for (AnnotateImageResponse imgResponse : responses) {
CropHintsAnnotation annotation = imgResponse.getCropHintsAnnotation();
for (CropHint hint : annotation.getCropHintsList()) {
for (Vertex vertex : hint.getBoundingPoly().getVerticesList()) {
actual.add(vertex.getX());
}
}
}
assertEquals(Arrays.asList(210, 476, 476, 210), actual);
}
Aggregations