Search in sources :

Example 81 with AnnotateImageRequest

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");
}
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 82 with AnnotateImageRequest

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");
}
Also used : AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) ArrayList(java.util.ArrayList) StatusRuntimeException(io.grpc.StatusRuntimeException) ImageSource(com.google.cloud.vision.v1.ImageSource) 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) CropHint(com.google.cloud.vision.v1.CropHint) Test(org.junit.Test)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)77 Image (com.google.cloud.vision.v1.Image)71 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)69 Feature (com.google.cloud.vision.v1.Feature)69 ArrayList (java.util.ArrayList)66 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)65 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)62 ByteString (com.google.protobuf.ByteString)44 ImageSource (com.google.cloud.vision.v1.ImageSource)41 FileInputStream (java.io.FileInputStream)32 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)26 IOException (java.io.IOException)13 SafeSearchAnnotation (com.google.cloud.vision.v1.SafeSearchAnnotation)11 WebDetection (com.google.cloud.vision.v1.WebDetection)11 ImageContext (com.google.cloud.vision.v1.ImageContext)10 LocationInfo (com.google.cloud.vision.v1.LocationInfo)10 Test (org.junit.Test)10 CropHint (com.google.cloud.vision.v1.CropHint)9 WebPage (com.google.cloud.vision.v1.WebDetection.WebPage)9