Search in sources :

Example 41 with ImageSource

use of com.google.cloud.vision.v1p4beta1.ImageSource 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)38 Image (com.google.cloud.vision.v1.Image)38 ImageSource (com.google.cloud.vision.v1.ImageSource)38 Feature (com.google.cloud.vision.v1.Feature)37 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)35 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)34 ArrayList (java.util.ArrayList)34 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)32 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)13 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)13 ByteString (com.google.protobuf.ByteString)11 IOException (java.io.IOException)8 SafeSearchAnnotation (com.google.cloud.vision.v1.SafeSearchAnnotation)7 LocationInfo (com.google.cloud.vision.v1.LocationInfo)6 WebDetection (com.google.cloud.vision.v1.WebDetection)6 CropHint (com.google.cloud.vision.v1.CropHint)5 ImageContext (com.google.cloud.vision.v1.ImageContext)5 Block (com.google.cloud.vision.v1.Block)4 ColorInfo (com.google.cloud.vision.v1.ColorInfo)4 CropHintsAnnotation (com.google.cloud.vision.v1.CropHintsAnnotation)4