use of com.google.cloud.retail.v2.ColorInfo in project java-vision by googleapis.
the class DetectPropertiesGcs method detectPropertiesGcs.
// Detects image properties such as color frequency from the specified remote image on Google
// Cloud Storage.
public static void detectPropertiesGcs(String gcsPath) throws IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Feature.Type.IMAGE_PROPERTIES).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
// the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.format("Error: %s%n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
for (ColorInfo color : colors.getColorsList()) {
System.out.format("fraction: %f%nr: %f, g: %f, b: %f%n", color.getPixelFraction(), color.getColor().getRed(), color.getColor().getGreen(), color.getColor().getBlue());
}
}
}
}
use of com.google.cloud.retail.v2.ColorInfo in project java-vision by googleapis.
the class ITSystemTest method detectPropertiesGcsTest.
@Test
public void detectPropertiesGcsTest() throws IOException {
List<AnnotateImageResponse> responses = getResponsesList("landmark/pofa.jpg", Type.IMAGE_PROPERTIES, true);
List<Float> actual = new ArrayList<>();
for (AnnotateImageResponse res : responses) {
DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
for (ColorInfo color : colors.getColorsList()) {
actual.add(color.getPixelFraction());
}
}
assertThat(actual).contains((float) 0.14140345);
}
Aggregations