Search in sources :

Example 91 with AnnotateImageResponse

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

the class ITSystemTest method detectLabelsTest.

@Test
public void detectLabelsTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("wakeupcat.jpg", Type.LABEL_DETECTION, false);
    List<String> actual = new ArrayList<>();
    for (AnnotateImageResponse res : responses) {
        for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
            actual.add(annotation.getDescription());
        }
    }
    assertThat(actual).contains("Whiskers");
}
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 92 with AnnotateImageResponse

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

the class ITSystemTest method detectFacesGcsTest.

@Test
public void detectFacesGcsTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("face/face_no_surprise.jpg", Type.FACE_DETECTION, true);
    for (AnnotateImageResponse res : responses) {
        for (FaceAnnotation annotation : res.getFaceAnnotationsList()) {
            assertEquals(Likelihood.LIKELY, annotation.getAngerLikelihood());
            assertEquals(Likelihood.VERY_UNLIKELY, annotation.getJoyLikelihood());
            assertEquals(Likelihood.LIKELY, annotation.getSurpriseLikelihood());
        }
    }
}
Also used : FaceAnnotation(com.google.cloud.vision.v1.FaceAnnotation) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) Test(org.junit.Test)

Example 93 with AnnotateImageResponse

use of com.google.cloud.vision.v1p3beta1.AnnotateImageResponse 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");
}
Also used : WebDetectionParams(com.google.cloud.vision.v1.WebDetectionParams) WebDetection(com.google.cloud.vision.v1.WebDetection) 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) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ImageSource(com.google.cloud.vision.v1.ImageSource) ImageContext(com.google.cloud.vision.v1.ImageContext) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse) Test(org.junit.Test)

Example 94 with AnnotateImageResponse

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

the class ITSystemTest method detectDocumentTextTest.

@Test
public void detectDocumentTextTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("text.jpg", Type.DOCUMENT_TEXT_DETECTION, false);
    String actual = "";
    for (AnnotateImageResponse imgResponse : responses) {
        TextAnnotation annotation = imgResponse.getFullTextAnnotation();
        actual = annotation.getText();
    }
    assertThat(actual).contains("After preparation is complete");
}
Also used : AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ByteString(com.google.protobuf.ByteString) TextAnnotation(com.google.cloud.vision.v1.TextAnnotation) Test(org.junit.Test)

Example 95 with AnnotateImageResponse

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

the class ITSystemTest method detectTextGcsTest.

@Test
public void detectTextGcsTest() throws IOException {
    List<AnnotateImageResponse> responses = getResponsesList("text/screen.jpg", Type.TEXT_DETECTION, true);
    List<String> actual = new ArrayList<>();
    for (AnnotateImageResponse res : responses) {
        for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
            actual.add(annotation.getDescription());
        }
    }
    String joinedActual = String.join(" ", actual);
    assertThat(joinedActual).contains("37%");
}
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)

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