Java Code Examples for com.google.cloud.vision.v1.AnnotateImageRequest#Builder

The following examples show how to use com.google.cloud.vision.v1.AnnotateImageRequest#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudVision.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Maps the {@link String} with encoded image data and the optional {@link ImageContext} into an
 * {@link AnnotateImageRequest}.
 *
 * @param uri Input element.
 * @param ctx optional image context.
 * @return a valid request.
 */
@Override
public AnnotateImageRequest mapToRequest(String uri, @Nullable ImageContext ctx) {
  AnnotateImageRequest.Builder builder = AnnotateImageRequest.newBuilder();
  if (ctx != null) {
    builder.setImageContext(ctx);
  }
  ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(uri).build();
  return builder
      .addAllFeatures(featureList)
      .setImage(Image.newBuilder().setSource(imgSource).build())
      .build();
}
 
Example 2
Source File: CloudVision.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Maps the {@link ByteString} with encoded image data and the optional {@link ImageContext}
 * into an {@link AnnotateImageRequest}.
 *
 * @param input Input element.
 * @param ctx optional image context.
 * @return a valid request.
 */
@Override
public AnnotateImageRequest mapToRequest(ByteString input, @Nullable ImageContext ctx) {
  AnnotateImageRequest.Builder builder = AnnotateImageRequest.newBuilder();
  if (ctx != null) {
    builder.setImageContext(ctx);
  }
  return builder
      .addAllFeatures(featureList)
      .setImage(Image.newBuilder().setContent(input).build())
      .build();
}
 
Example 3
Source File: CloudVision.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Maps {@link KV} of {@link String} (GCS URI to the image) and {@link ImageContext} to a valid
 * {@link AnnotateImageRequest}.
 *
 * @param input Input element.
 * @param ctx optional image context, ignored here since the input holds context.
 * @return a valid request.
 */
@Override
public AnnotateImageRequest mapToRequest(
    KV<String, ImageContext> input, @Nullable ImageContext ctx) {
  ImageSource imageSource = ImageSource.newBuilder().setGcsImageUri(input.getKey()).build();
  Image image = Image.newBuilder().setSource(imageSource).build();
  AnnotateImageRequest.Builder builder =
      AnnotateImageRequest.newBuilder().setImage(image).addAllFeatures(featureList);
  if (input.getValue() != null) {
    builder.setImageContext(input.getValue());
  }
  return builder.build();
}
 
Example 4
Source File: CloudVision.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Maps {@link KV} of {@link ByteString} (encoded image contents) and {@link ImageContext} to
 * {@link AnnotateImageRequest}.
 *
 * @param input Input element.
 * @param ctx optional image context.
 * @return valid request element.
 */
@Override
public AnnotateImageRequest mapToRequest(
    KV<ByteString, ImageContext> input, @Nullable ImageContext ctx) {
  Image image = Image.newBuilder().setContent(input.getKey()).build();
  AnnotateImageRequest.Builder builder =
      AnnotateImageRequest.newBuilder().setImage(image).addAllFeatures(featureList);
  if (input.getValue() != null) {
    builder.setImageContext(input.getValue());
  }
  return builder.build();
}
 
Example 5
Source File: GoogleVisionCache.java    From TweetwallFX with MIT License 5 votes vote down vote up
private AnnotateImageRequest createImageRequest(final String imageUri) {
    final AnnotateImageRequest.Builder builder = AnnotateImageRequest.newBuilder()
            .setImage(Image.newBuilder()
                    .setSource(ImageSource.newBuilder()
                            .setImageUri(imageUri)));

    GOOGLE_SETTINGS.getCloudVision().getFeatureTypes().stream()
            .map(GoogleVisionCache::convertFeatureType)
            .forEach(builder.addFeaturesBuilder()::setType);

    return builder.build();
}