Search in sources :

Example 16 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ProductSetManagement method createProductSet.

// [START vision_product_search_create_product_set]
/**
 * Create a product set
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productSetId - Id of the product set.
 * @param productSetDisplayName - Display name of the product set.
 * @throws IOException - on I/O errors.
 */
public static void createProductSet(String projectId, String computeRegion, String productSetId, String productSetDisplayName) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // A resource that represents Google Cloud Platform location.
        String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
        // Create a product set with the product set specification in the region.
        ProductSet myProductSet = ProductSet.newBuilder().setDisplayName(productSetDisplayName).build();
        CreateProductSetRequest request = CreateProductSetRequest.newBuilder().setParent(formattedParent).setProductSet(myProductSet).setProductSetId(productSetId).build();
        ProductSet productSet = client.createProductSet(request);
        // Display the product set information
        System.out.println(String.format("Product set name: %s", productSet.getName()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) CreateProductSetRequest(com.google.cloud.vision.v1.CreateProductSetRequest) ProductSet(com.google.cloud.vision.v1.ProductSet)

Example 17 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ReferenceImageManagement method getReferenceImage.

// [END vision_product_search_list_reference_images]
// [START vision_product_search_get_reference_image]
/**
 * Get info about a reference image.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param referenceImageId - Id of the image.
 * @throws IOException - on I/O errors.
 */
public static void getReferenceImage(String projectId, String computeRegion, String productId, String referenceImageId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the reference image.
        String formattedName = ImageName.format(projectId, computeRegion, productId, referenceImageId);
        // Get complete detail of the reference image.
        ReferenceImage image = client.getReferenceImage(formattedName);
        // Display the reference image information.
        System.out.println(String.format("Reference image name: %s", image.getName()));
        System.out.println(String.format("Reference image id: %s", image.getName().substring(image.getName().lastIndexOf('/') + 1)));
        System.out.println(String.format("Reference image uri: %s", image.getUri()));
        System.out.println(String.format("Reference image bounding polygons: %s \n", image.getBoundingPolysList().toString()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage)

Example 18 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ReferenceImageManagement method createReferenceImage.

// [START vision_product_search_create_reference_image]
/**
 * Create a reference image.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param referenceImageId - Id of the image.
 * @param gcsUri - Google Cloud Storage path of the input image.
 * @throws IOException - on I/O errors.
 */
public static void createReferenceImage(String projectId, String computeRegion, String productId, String referenceImageId, String gcsUri) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedParent = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Create a reference image.
        ReferenceImage referenceImage = ReferenceImage.newBuilder().setUri(gcsUri).build();
        ReferenceImage image = client.createReferenceImage(formattedParent, referenceImage, referenceImageId);
        // Display the reference image information.
        System.out.println(String.format("Reference image name: %s", image.getName()));
        System.out.println(String.format("Reference image uri: %s", image.getUri()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage)

Example 19 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ReferenceImageManagement method deleteReferenceImage.

// [END vision_product_search_get_reference_image]
// [START vision_product_search_delete_reference_image]
/**
 * Delete a reference image.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param referenceImageId - Id of the image.
 * @throws IOException - on I/O errors.
 */
public static void deleteReferenceImage(String projectId, String computeRegion, String productId, String referenceImageId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the reference image.
        String formattedName = ImageName.format(projectId, computeRegion, productId, referenceImageId);
        // Delete the reference image.
        client.deleteReferenceImage(formattedName);
        System.out.println("Reference image deleted from product.");
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient)

Example 20 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class PurgeProducts method purgeOrphanProducts.

// Delete the product and all its reference images.
public static void purgeOrphanProducts(String projectId, String computeRegion) throws Exception {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        String parent = LocationName.format(projectId, computeRegion);
        // The purge operation is async.
        PurgeProductsRequest request = PurgeProductsRequest.newBuilder().setDeleteOrphanProducts(true).setForce(true).setParent(parent).build();
        OperationFuture response = client.purgeProductsAsync(request);
        response.getPollingFuture().get(180, TimeUnit.SECONDS);
        System.out.println("Orphan products deleted.");
    }
}
Also used : PurgeProductsRequest(com.google.cloud.vision.v1.PurgeProductsRequest) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) OperationFuture(com.google.api.gax.longrunning.OperationFuture)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.vision.v1.Product)6 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 BatchOperationMetadata (com.google.cloud.vision.v1.BatchOperationMetadata)2 CreateProductSetRequest (com.google.cloud.vision.v1.CreateProductSetRequest)2 KeyValue (com.google.cloud.vision.v1.Product.KeyValue)2 PurgeProductsRequest (com.google.cloud.vision.v1.PurgeProductsRequest)2 OperationFuture (com.google.api.gax.longrunning.OperationFuture)1 AddProductToProductSetRequest (com.google.cloud.vision.v1.AddProductToProductSetRequest)1 CreateProductRequest (com.google.cloud.vision.v1.CreateProductRequest)1 CreateReferenceImageRequest (com.google.cloud.vision.v1.CreateReferenceImageRequest)1 Builder (com.google.cloud.vision.v1.ImportProductSetsGcsSource.Builder)1 ImportProductSetsInputConfig (com.google.cloud.vision.v1.ImportProductSetsInputConfig)1 ImportProductSetsResponse (com.google.cloud.vision.v1.ImportProductSetsResponse)1 ProductSetPurgeConfig (com.google.cloud.vision.v1.ProductSetPurgeConfig)1 Empty (com.google.protobuf.Empty)1 FieldMask (com.google.protobuf.FieldMask)1 BeforeClass (org.junit.BeforeClass)1