Search in sources :

Example 61 with Image

use of com.google.cloud.automl.v1beta1.Image in project cloudbreak by hortonworks.

the class OpenStackImageVerifier method getStatus.

public ImageStatus getStatus(OSClient<?> osClient, String name) {
    ImageStatus imageStatus;
    List<? extends Image> images = osClient.imagesV2().list(Collections.singletonMap("name", name));
    if (images == null || images.isEmpty()) {
        imageStatus = null;
        LOGGER.error("OpenStack image: {} not found", name);
        List<? extends Image> allImages = osClient.imagesV2().list();
        if (allImages != null) {
            for (Image image : allImages) {
                LOGGER.info("Available images: {}, entry: {}", image.getName(), image);
            }
        }
        LOGGER.warn("OpenStack image: {} not found", name);
    } else if (images.size() > 1) {
        for (Image image : images) {
            LOGGER.info("Multiple images found: {}, entry: {}", image.getName(), image);
        }
        List<String> imageIds = images.stream().map(Image::getId).collect(Collectors.toList());
        throw new CloudConnectorException(String.format("Multiple OpenStack images found with ids: %s, image name: %s", String.join(", ", imageIds), name));
    } else {
        LOGGER.info("OpenStack Image found: {}, entry: {}", name, images);
        imageStatus = images.get(0).getStatus();
    }
    return imageStatus;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ImageStatus(org.openstack4j.model.image.v2.Image.ImageStatus) List(java.util.List) Image(org.openstack4j.model.image.v2.Image)

Example 62 with Image

use of com.google.cloud.automl.v1beta1.Image in project cloudbreak by hortonworks.

the class OpenStackSetup method checkImageStatus.

@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    String imageName = image.getImageName();
    OSClient osClient = openStackClient.createOSClient(authenticatedContext);
    Image.ImageStatus imageStatus = openStackImageVerifier.getStatus(osClient, imageName);
    ImageStatusResult imageStatusResult;
    switch(imageStatus) {
        case ACTIVE:
            imageStatusResult = new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
            break;
        case QUEUED:
        case SAVING:
            imageStatusResult = new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
            break;
        default:
            imageStatusResult = new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED);
            break;
    }
    LOGGER.info("OpenStack image result. name: {}, imageStatus: {}, imageStatusResult: {}", imageName, imageStatus, imageStatusResult);
    return imageStatusResult;
}
Also used : OSClient(org.openstack4j.api.OSClient) Image(org.openstack4j.model.image.v2.Image) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 63 with Image

use of com.google.cloud.automl.v1beta1.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)

Example 64 with Image

use of com.google.cloud.automl.v1beta1.Image in project java-docs-samples by GoogleCloudPlatform.

the class Detect method detectWebEntitiesGcs.

/**
 * Find web entities given the remote image on Google Cloud Storage.
 * @param gcsPath The path to the remote file on Google Cloud Storage to detect web entities.
 * @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 detectWebEntitiesGcs(String gcsPath, PrintStream out) throws Exception, IOException {
    // Instantiates a client
    try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
        // Set the image source to the given gs uri
        ImageSource imageSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
        // Build the image
        Image image = Image.newBuilder().setSource(imageSource).build();
        // Create the request with the image and the specified feature: web detection
        AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(Feature.newBuilder().setType(Type.WEB_DETECTION)).setImage(image).build();
        // Perform the request
        BatchAnnotateImagesResponse response = client.batchAnnotateImages(Arrays.asList(request));
        // Display the results
        response.getResponsesList().stream().forEach(r -> r.getWebDetection().getWebEntitiesList().stream().forEach(entity -> {
            System.out.format("Description: %s\n", entity.getDescription());
            System.out.format("Score: %f\n", entity.getScore());
        }));
    }
}
Also used : WebDetectionParams(com.google.cloud.vision.v1.WebDetectionParams) Arrays(java.util.Arrays) WebPage(com.google.cloud.vision.v1.WebDetection.WebPage) Paragraph(com.google.cloud.vision.v1.Paragraph) ArrayList(java.util.ArrayList) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) WebLabel(com.google.cloud.vision.v1.WebDetection.WebLabel) CropHint(com.google.cloud.vision.v1.CropHint) PrintStream(java.io.PrintStream) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ImageSource(com.google.cloud.vision.v1.ImageSource) WebDetection(com.google.cloud.vision.v1.WebDetection) Type(com.google.cloud.vision.v1.Feature.Type) LocationInfo(com.google.cloud.vision.v1.LocationInfo) FaceAnnotation(com.google.cloud.vision.v1.FaceAnnotation) Block(com.google.cloud.vision.v1.Block) CropHintsAnnotation(com.google.cloud.vision.v1.CropHintsAnnotation) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Feature(com.google.cloud.vision.v1.Feature) Symbol(com.google.cloud.vision.v1.Symbol) ColorInfo(com.google.cloud.vision.v1.ColorInfo) ByteString(com.google.protobuf.ByteString) List(java.util.List) TextAnnotation(com.google.cloud.vision.v1.TextAnnotation) Image(com.google.cloud.vision.v1.Image) WebEntity(com.google.cloud.vision.v1.WebDetection.WebEntity) ImageContext(com.google.cloud.vision.v1.ImageContext) SafeSearchAnnotation(com.google.cloud.vision.v1.SafeSearchAnnotation) Page(com.google.cloud.vision.v1.Page) DominantColorsAnnotation(com.google.cloud.vision.v1.DominantColorsAnnotation) Word(com.google.cloud.vision.v1.Word) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) ImageSource(com.google.cloud.vision.v1.ImageSource) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) Image(com.google.cloud.vision.v1.Image) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Example 65 with Image

use of com.google.cloud.automl.v1beta1.Image in project java-docs-samples by GoogleCloudPlatform.

the class Detect method detectCropHintsGcs.

/**
 * Suggests a region to crop to for a remote file on Google Cloud Storage.
 *
 * @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
 * @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 detectCropHintsGcs(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.CROP_HINTS).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;
            }
            // For full list of available annotations, see http://g.co/cloud/vision/docs
            CropHintsAnnotation annotation = res.getCropHintsAnnotation();
            for (CropHint hint : annotation.getCropHintsList()) {
                out.println(hint.getBoundingPoly());
            }
        }
    }
}
Also used : AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) CropHintsAnnotation(com.google.cloud.vision.v1.CropHintsAnnotation) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) ImageSource(com.google.cloud.vision.v1.ImageSource) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) Image(com.google.cloud.vision.v1.Image) CropHint(com.google.cloud.vision.v1.CropHint) Feature(com.google.cloud.vision.v1.Feature) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)75 Image (com.google.cloud.vision.v1.Image)75 Feature (com.google.cloud.vision.v1.Feature)73 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)72 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)69 ArrayList (java.util.ArrayList)69 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)66 ByteString (com.google.protobuf.ByteString)52 ImageSource (com.google.cloud.vision.v1.ImageSource)41 FileInputStream (java.io.FileInputStream)32 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)26 IOException (java.io.IOException)21 ImageContext (com.google.cloud.vision.v1.ImageContext)14 SafeSearchAnnotation (com.google.cloud.vision.v1.SafeSearchAnnotation)11 WebDetection (com.google.cloud.vision.v1.WebDetection)11 LocationInfo (com.google.cloud.vision.v1.LocationInfo)10 Arrays (java.util.Arrays)10 Image (com.google.cloud.compute.v1.Image)9 ImagesClient (com.google.cloud.compute.v1.ImagesClient)9