Search in sources :

Example 16 with Image

use of com.ibm.dtfj.image.j9.Image in project google-cloud-java by GoogleCloudPlatform.

the class AnnotateImage method main.

public static void main(String... args) throws Exception {
    // Instantiates a client
    ImageAnnotatorClient vision = ImageAnnotatorClient.create();
    // The path to the image file to annotate
    // for example "./resources/wakeupcat.jpg";
    String fileName = "your/image/path.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.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());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ByteString(com.google.protobuf.ByteString) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) Map(java.util.Map) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Example 17 with Image

use of com.ibm.dtfj.image.j9.Image in project openstack4j by ContainX.

the class ImageV2Tests method testGetImage.

public void testGetImage() throws IOException {
    respondWith(IMAGE_JSON);
    String id = "8a2ea42d-06b5-42c2-a54d-97105420f2bb";
    Image image = osv3().imagesV2().get(id);
    assertNotNull(image);
    assertNotNull(image.getId());
    assertEquals(image.getId(), id);
}
Also used : Image(org.openstack4j.model.image.v2.Image)

Example 18 with Image

use of com.ibm.dtfj.image.j9.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ImageIT method setupBeforeEach.

@BeforeEach
public void setupBeforeEach() throws ClientException {
    imageTests = new ImageTests();
    imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v2, rootPage, defaultPageTemplate, clientlibs, new Image());
}
Also used : ImageTests(com.adobe.cq.wcm.core.components.it.seljup.tests.image.ImageTests) Image(com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with Image

use of com.ibm.dtfj.image.j9.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.

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());
}
Also used : ImageTests(com.adobe.cq.wcm.core.components.it.seljup.tests.image.ImageTests) Image(com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v1.Image) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with Image

use of com.ibm.dtfj.image.j9.Image in project java-docs-samples by GoogleCloudPlatform.

the class Detect method detectWebDetectionsGcs.

// [END vision_detect_web]
// [START vision_detect_web_uri]
/**
 * Detects whether the remote image on Google Cloud Storage has features you would want to
 * moderate.
 *
 * @param gcsPath The path to the remote on Google Cloud Storage file to detect web annotations.
 * @param out A {@link PrintStream} to write the results to.
 * @throws Exception on errors while closing the client.
 * @throws IOException on Input/Output errors.
 */
public static void detectWebDetectionsGcs(String gcsPath, PrintStream out) throws Exception, 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(Type.WEB_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();
        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                out.printf("Error: %s\n", res.getError().getMessage());
                return;
            }
            // Search the web for usages of the image. You could use these signals later
            // for user input moderation or linking external references.
            // For a full list of available annotations, see http://g.co/cloud/vision/docs
            WebDetection annotation = res.getWebDetection();
            out.println("Entity:Id:Score");
            out.println("===============");
            for (WebEntity entity : annotation.getWebEntitiesList()) {
                out.println(entity.getDescription() + " : " + entity.getEntityId() + " : " + entity.getScore());
            }
            for (WebLabel label : annotation.getBestGuessLabelsList()) {
                out.format("\nBest guess label: %s", label.getLabel());
            }
            out.println("\nPages with matching images: Score\n==");
            for (WebPage page : annotation.getPagesWithMatchingImagesList()) {
                out.println(page.getUrl() + " : " + page.getScore());
            }
            out.println("\nPages with partially matching images: Score\n==");
            for (WebImage image : annotation.getPartialMatchingImagesList()) {
                out.println(image.getUrl() + " : " + image.getScore());
            }
            out.println("\nPages with fully matching images: Score\n==");
            for (WebImage image : annotation.getFullMatchingImagesList()) {
                out.println(image.getUrl() + " : " + image.getScore());
            }
            out.println("\nPages with visually similar images: Score\n==");
            for (WebImage image : annotation.getVisuallySimilarImagesList()) {
                out.println(image.getUrl() + " : " + image.getScore());
            }
        }
    }
}
Also used : WebDetection(com.google.cloud.vision.v1.WebDetection) WebPage(com.google.cloud.vision.v1.WebDetection.WebPage) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) ArrayList(java.util.ArrayList) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) WebEntity(com.google.cloud.vision.v1.WebDetection.WebEntity) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) WebLabel(com.google.cloud.vision.v1.WebDetection.WebLabel) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ImageSource(com.google.cloud.vision.v1.ImageSource) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)28 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)28 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)28 Feature (com.google.cloud.vision.v1.Feature)28 Image (com.google.cloud.vision.v1.Image)28 ArrayList (java.util.ArrayList)28 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)27 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)25 ByteString (com.google.protobuf.ByteString)17 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)16 ImageSource (com.google.cloud.vision.v1.ImageSource)15 FileInputStream (java.io.FileInputStream)14 WebPage (com.google.cloud.vision.v1.WebDetection.WebPage)8 Block (com.google.cloud.vision.v1.Block)6 ColorInfo (com.google.cloud.vision.v1.ColorInfo)6 CropHint (com.google.cloud.vision.v1.CropHint)6 CropHintsAnnotation (com.google.cloud.vision.v1.CropHintsAnnotation)6 DominantColorsAnnotation (com.google.cloud.vision.v1.DominantColorsAnnotation)6 FaceAnnotation (com.google.cloud.vision.v1.FaceAnnotation)6 LocationInfo (com.google.cloud.vision.v1.LocationInfo)6