Search in sources :

Example 86 with AnnotateImageResponse

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");
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) LocalizedObjectAnnotation(com.google.cloud.vision.v1.LocalizedObjectAnnotation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 87 with AnnotateImageResponse

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");
}
Also used : WebDetection(com.google.cloud.vision.v1.WebDetection) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 88 with AnnotateImageResponse

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());
    }
}
Also used : SafeSearchAnnotation(com.google.cloud.vision.v1.SafeSearchAnnotation) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) Test(org.junit.Test)

Example 89 with AnnotateImageResponse

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);
}
Also used : WebDetectionParams(com.google.cloud.vision.v1.WebDetectionParams) WebDetection(com.google.cloud.vision.v1.WebDetection) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) FileInputStream(java.io.FileInputStream) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ImageContext(com.google.cloud.vision.v1.ImageContext) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse) Test(org.junit.Test)

Example 90 with AnnotateImageResponse

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);
}
Also used : Vertex(com.google.cloud.vision.v1.Vertex) CropHintsAnnotation(com.google.cloud.vision.v1.CropHintsAnnotation) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) CropHint(com.google.cloud.vision.v1.CropHint) Test(org.junit.Test)

Aggregations

AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)91 ArrayList (java.util.ArrayList)73 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)63 Feature (com.google.cloud.vision.v1.Feature)62 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)61 Image (com.google.cloud.vision.v1.Image)61 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)60 ByteString (com.google.protobuf.ByteString)53 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)34 ImageSource (com.google.cloud.vision.v1.ImageSource)31 FileInputStream (java.io.FileInputStream)25 Test (org.junit.Test)23 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)22 SafeSearchAnnotation (com.google.cloud.vision.v1.SafeSearchAnnotation)9 WebDetection (com.google.cloud.vision.v1.WebDetection)8 IOException (java.io.IOException)8 Block (com.google.cloud.vision.v1.Block)6 ColorInfo (com.google.cloud.vision.v1.ColorInfo)6 CropHint (com.google.cloud.vision.v1.CropHint)6 CropHintsAnnotation (com.google.cloud.vision.v1.CropHintsAnnotation)6