com.google.api.services.vision.v1.model.EntityAnnotation

Here are the examples of the java api class com.google.api.services.vision.v1.model.EntityAnnotation taken from open source projects.

1. LabelApp#printLabels()

Project: cloud-vision
Source File: LabelApp.java
View license
/**
   * Prints the labels received from the Vision API.
   */
public static void printLabels(PrintStream out, Path imagePath, List<EntityAnnotation> labels) {
    out.printf("Labels for image %s:\n", imagePath);
    for (EntityAnnotation label : labels) {
        out.printf("\t%s (score: %.3f)\n", label.getDescription(), label.getScore());
    }
    if (labels.isEmpty()) {
        out.println("\tNo labels found.");
    }
}

2. LabelAppIT#labelImage_cat_returnsCatDescription()

Project: cloud-vision
Source File: LabelAppIT.java
View license
@Test
public void labelImage_cat_returnsCatDescription() throws Exception {
    List<EntityAnnotation> labels = appUnderTest.labelImage(Paths.get("../../data/label/cat.jpg"), MAX_LABELS);
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (EntityAnnotation label : labels) {
        builder.add(label.getDescription());
    }
    ImmutableSet<String> descriptions = builder.build();
    assertThat(descriptions).named("cat.jpg labels").contains("cat");
}

3. DetectLandmark#main()

Project: cloud-vision
Source File: DetectLandmark.java
View license
// [START run_application]
/**
   * Annotates an image using the Vision API.
   */
public static void main(String[] args) throws IOException, GeneralSecurityException {
    if (args.length != 1) {
        System.err.println("Usage:");
        System.err.printf("\tjava %s gs://<bucket_name>/<object_name>\n", DetectLandmark.class.getCanonicalName());
        System.exit(1);
    } else if (!args[0].toLowerCase().startsWith("gs://")) {
        System.err.println("Google Cloud Storage url must start with 'gs://'.");
        System.exit(1);
    }
    DetectLandmark app = new DetectLandmark(getVisionService());
    List<EntityAnnotation> landmarks = app.identifyLandmark(args[0], MAX_RESULTS);
    System.out.printf("Found %d landmark%s\n", landmarks.size(), landmarks.size() == 1 ? "" : "s");
    for (EntityAnnotation annotation : landmarks) {
        System.out.printf("\t%s\n", annotation.getDescription());
    }
}

4. TextApp#extractDescriptions()

Project: cloud-vision
Source File: TextApp.java
View license
/**
   * Extracts as a combinded string, all the descriptions from text annotations on an {@code image}.
   */
public Word extractDescriptions(ImageText image) {
    String document = "";
    for (EntityAnnotation text : image.textAnnotations()) {
        document += text.getDescription();
    }
    if (document.equals("")) {
        System.out.printf("%s had no discernible text.\n", image.path());
    }
    // Output a progress indicator.
    System.out.print('.');
    System.out.flush();
    return Word.builder().path(image.path()).word(document).build();
}