use of com.google.cloud.compute.v1.Image in project aem-core-wcm-components by adobe.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v1, rootPage, defaultPageTemplate, clientlibs, new Image());
}
use of com.google.cloud.compute.v1.Image in project aem-core-wcm-components by adobe.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
clientlibs = "core.wcm.components.image.v3";
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v3, rootPage, defaultPageTemplate, clientlibs, new Image());
}
use of com.google.cloud.compute.v1.Image in project java-vision by googleapis.
the class QuickstartSample method main.
public static void main(String... args) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {
// The path to the image file to annotate
String fileName = "./resources/wakeupcat.jpg";
// Reads the image file into memory
Path path = Paths.get(fileName);
byte[] data = Files.readAllBytes(path);
ByteString imgBytes = ByteString.copyFrom(data);
// Builds the image annotation request
List<AnnotateImageRequest> requests = new ArrayList<>();
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);
// Performs label detection on the image file
BatchAnnotateImagesResponse response = vision.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 (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
annotation.getAllFields().forEach((k, v) -> System.out.format("%s : %s%n", k, v.toString()));
}
}
}
}
use of com.google.cloud.compute.v1.Image in project java-vision by googleapis.
the class DetectCropHints method detectCropHints.
// Suggests a region to crop to for a local file.
public static void detectCropHints(String filePath) throws IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Feature.Type.CROP_HINTS).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
CropHintsAnnotation annotation = res.getCropHintsAnnotation();
for (CropHint hint : annotation.getCropHintsList()) {
System.out.println(hint.getBoundingPoly());
}
}
}
}
use of com.google.cloud.compute.v1.Image in project java-vision by googleapis.
the class ITSystemTest method detectWebEntitiesGcsTest.
@Test
public void detectWebEntitiesGcsTest() throws IOException {
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(SAMPLE_BUCKET + "landmark/pofa.jpg").build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).setMaxResults(MAX_RESULTS).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request));
List<AnnotateImageResponse> responses = response.getResponsesList();
List<String> actual = new ArrayList<>();
for (AnnotateImageResponse imgResponse : responses) {
for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) {
actual.add(entity.getDescription());
}
}
assertThat(actual).contains("The Palace Of Fine Arts");
}
Aggregations