public static void main(String... args) throws Exception { ImageAnnotatorClient vision = ImageAnnotatorClient.create(); Image img = Image.newBuilder().setContent(imgBytes).build(); Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build(); AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); requests.add(request); BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests); List<AnnotateImageResponse> responses = response.getResponsesList(); if (res.hasError()) { System.out.printf("Error: %s\n", res.getError().getMessage()); return; for (EntityAnnotation annotation : res.getLabelAnnotationsList()) { for (Map.Entry<FieldDescriptor, Object> entry : annotation.getAllFields().entrySet()) { System.out.printf("%s : %s\n", entry.getKey(), entry.getValue());
@java.lang.Override public com.google.cloud.vision.v1.Feature buildPartial() { com.google.cloud.vision.v1.Feature result = new com.google.cloud.vision.v1.Feature(this); result.type_ = type_; result.maxResults_ = maxResults_; result.model_ = model_; onBuilt(); return result; }
public Builder mergeFrom(com.google.cloud.vision.v1.Feature other) { if (other == com.google.cloud.vision.v1.Feature.getDefaultInstance()) return this; if (other.type_ != 0) { setTypeValue(other.getTypeValue()); } if (other.getMaxResults() != 0) { setMaxResults(other.getMaxResults()); } if (!other.getModel().isEmpty()) { model_ = other.model_; onChanged(); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.cloud.vision.v1.Feature)) { return super.equals(obj); } com.google.cloud.vision.v1.Feature other = (com.google.cloud.vision.v1.Feature) obj; boolean result = true; result = result && type_ == other.type_; result = result && (getMaxResults() == other.getMaxResults()); result = result && getModel().equals(other.getModel()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + TYPE_FIELD_NUMBER; hash = (53 * hash) + type_; hash = (37 * hash) + MAX_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getMaxResults(); hash = (37 * hash) + MODEL_FIELD_NUMBER; hash = (53 * hash) + getModel().hashCode(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
/** * * * <pre> * Model to use for the feature. * Supported values: "builtin/stable" (the default if unset) and * "builtin/latest". * </pre> * * <code>string model = 3;</code> */ public Builder clearModel() { model_ = getDefaultInstance().getModel(); onChanged(); return this; } /**
Image img = Image.newBuilder().setContent(imgBytes).build(); Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build(); AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); requests.add(request); try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); List<AnnotateImageResponse> responses = response.getResponsesList(); client.close(); if (res.hasError()) { out.printf("Error: %s\n", res.getError().getMessage()); return; TextAnnotation annotation = res.getFullTextAnnotation(); for (Page page: annotation.getPagesList()) { String pageText = "";
IOException { try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { Image image = Image.newBuilder().setContent(contents).build(); AnnotateImageRequest request = AnnotateImageRequest.newBuilder() .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION)) .setImage(image) .build(); BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request)); response.getResponsesList().stream() .forEach(r -> r.getWebDetection().getWebEntitiesList().stream() .forEach(entity -> { out.format("Description: %s\n", entity.getDescription());
Image img = Image.newBuilder().setContent(imgBytes).build(); AnnotateImageRequest request = AnnotateImageRequest.newBuilder() .addFeatures(Feature.newBuilder().setType(Type.OBJECT_LOCALIZATION)) .setImage(img) .build(); requests.add(request); try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); List<AnnotateImageResponse> responses = response.getResponsesList(); for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) { out.format("Object name: %s\n", entity.getName()); out.format("Confidence: %s\n", entity.getScore());
public static void executeNoCatch() throws Exception { try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { String gcsImageUri = "gs://gapic-toolkit/President_Barack_Obama.jpg"; ImageSource source = ImageSource.newBuilder().setGcsImageUri(gcsImageUri).build(); Image image = Image.newBuilder().setSource(source).build(); Feature.Type type = Feature.Type.FACE_DETECTION; Feature featuresElement = Feature.newBuilder().setType(type).build(); List<Feature> features = Arrays.asList(featuresElement); AnnotateImageRequest requestsElement = AnnotateImageRequest.newBuilder().setImage(image).addAllFeatures(features).build(); List<AnnotateImageRequest> requests = Arrays.asList(requestsElement); BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); } }
Image image = Image.newBuilder().setContent(imgBytes).build(); .map((featureType) -> Feature.newBuilder().setType(featureType).build()) .collect(Collectors.toList()); AnnotateImageRequest.newBuilder() .addAllFeatures(featureList) .setImage(image)) .build(); BatchAnnotateImagesResponse batchResponse = this.imageAnnotatorClient.batchAnnotateImages(request); List<AnnotateImageResponse> annotateImageResponses = batchResponse.getResponsesList();
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { List<AsyncAnnotateFileRequest> requests = new ArrayList<>(); Feature feature = Feature.newBuilder().setType(Feature.Type.DOCUMENT_TEXT_DETECTION).build(); client.asyncBatchAnnotateFilesAsync(requests); System.out.format("\nText: %s\n", annotateImageResponse.getFullTextAnnotation().getText()); } else { System.out.println("No MATCH");
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
@java.lang.Override public com.google.cloud.vision.v1.Feature getDefaultInstanceForType() { return com.google.cloud.vision.v1.Feature.getDefaultInstance(); }
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return com.google.cloud.vision.v1.Feature.getDescriptor().getEnumTypes().get(0); }
Image img = Image.newBuilder().setSource(imgSource).build(); Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build(); AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); requests.add(request); try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); List<AnnotateImageResponse> responses = response.getResponsesList(); client.close(); if (res.hasError()) { out.printf("Error: %s\n", res.getError().getMessage()); return; TextAnnotation annotation = res.getFullTextAnnotation(); for (Page page: annotation.getPagesList()) { String pageText = "";
IOException { try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { .build(); Image image = Image.newBuilder().setSource(imageSource).build(); AnnotateImageRequest request = AnnotateImageRequest.newBuilder() .addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION)) .setImage(image) .build(); BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request)); response.getResponsesList().stream() .forEach(r -> r.getWebDetection().getWebEntitiesList().stream() .forEach(entity -> { System.out.format("Description: %s\n", entity.getDescription());
Image img = Image.newBuilder().setSource(imgSource).build(); AnnotateImageRequest.newBuilder() .addFeatures(Feature.newBuilder().setType(Type.OBJECT_LOCALIZATION)) .setImage(img) .build(); requests.add(request); try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) { BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests); List<AnnotateImageResponse> responses = response.getResponsesList(); client.close(); for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) { out.format("Object name: %s\n", entity.getName()); out.format("Confidence: %s\n", entity.getScore());
Image image = Image.newBuilder().setContent(imgBytes).build(); .map((featureType) -> Feature.newBuilder().setType(featureType).build()) .collect(Collectors.toList()); AnnotateImageRequest.newBuilder() .addAllFeatures(featureList) .setImage(image)) .build(); BatchAnnotateImagesResponse batchResponse = this.imageAnnotatorClient.batchAnnotateImages(request); List<AnnotateImageResponse> annotateImageResponses = batchResponse.getResponsesList();
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }