Search in sources :

Example 41 with AnnotateImageResponse

use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.

the class ITSystemTest method detectLandmarksTest.

@Test
public void detectLandmarksTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("landmark.jpg", Type.LANDMARK_DETECTION, false);
    List<String> actual = new ArrayList<>();
    for (AnnotateImageResponse res : responses) {
        for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
            actual.add(annotation.getDescription());
        }
    }
    assertThat(actual).contains("Palace of Fine Arts");
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) Test(org.junit.Test)

Example 42 with AnnotateImageResponse

use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.

the class ITSystemTest method detectTextTest.

@Test
public void detectTextTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("text.jpg", Type.TEXT_DETECTION, false);
    List<String> actual = new ArrayList<>();
    for (AnnotateImageResponse res : responses) {
        for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
            actual.add(annotation.getDescription());
        }
    }
    assertThat(actual).contains("PS4");
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) Test(org.junit.Test)

Example 43 with AnnotateImageResponse

use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.

the class ITSystemTest method detectLandmarksGcsTest.

@Test
public void detectLandmarksGcsTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("landmark/pofa.jpg", Type.LANDMARK_DETECTION, true);
    List<String> actual = new ArrayList<>();
    for (AnnotateImageResponse res : responses) {
        for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
            actual.add(annotation.getDescription());
        }
    }
    assertThat(actual).contains("Palace of Fine Arts");
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) Test(org.junit.Test)

Example 44 with AnnotateImageResponse

use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.

the class ITSystemTest method addResponsesToList.

private List<String> addResponsesToList(AnnotateImageRequest request) {
    List<String> actual = new ArrayList<>();
    BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request));
    List<AnnotateImageResponse> responses = response.getResponsesList();
    for (AnnotateImageResponse res : responses) {
        if (res.getError().getCode() == 14) {
            throw new StatusRuntimeException(Status.UNAVAILABLE);
        }
        for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
            actual.add(annotation.getDescription());
        }
    }
    return actual;
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Example 45 with AnnotateImageResponse

use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse in project java-vision by googleapis.

the class ITSystemTest method detectPropertiesTest.

@Test
public void detectPropertiesTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("landmark.jpg", Type.IMAGE_PROPERTIES, false);
    List<Float> actual = new ArrayList<>();
    for (AnnotateImageResponse res : responses) {
        DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
        for (ColorInfo color : colors.getColorsList()) {
            actual.add(color.getPixelFraction());
        }
    }
    assertThat(actual).contains((float) 0.14140345);
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) DominantColorsAnnotation(com.google.cloud.vision.v1.DominantColorsAnnotation) ColorInfo(com.google.cloud.vision.v1.ColorInfo) 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