Search in sources :

Example 6 with ReferenceImage

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

the class ProductSearchClientTest method listReferenceImagesTest2.

@Test
public void listReferenceImagesTest2() throws Exception {
    ReferenceImage responsesElement = ReferenceImage.newBuilder().build();
    ListReferenceImagesResponse expectedResponse = ListReferenceImagesResponse.newBuilder().setNextPageToken("").addAllReferenceImages(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListReferenceImagesPagedResponse pagedListResponse = client.listReferenceImages(parent);
    List<ReferenceImage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getReferenceImagesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockProductSearch.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListReferenceImagesRequest actualRequest = ((ListReferenceImagesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListReferenceImagesPagedResponse(com.google.cloud.vision.v1.ProductSearchClient.ListReferenceImagesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 7 with ReferenceImage

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

the class ImportProductSets method importProductSets.

// [START vision_product_search_import_product_images]
/**
 * Import images of different products in the product set.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param gcsUri - Google Cloud Storage URI.Target files must be in Product Search CSV format.
 * @throws Exception - on client errors.
 */
public static void importProductSets(String projectId, String computeRegion, String gcsUri) throws Exception {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // A resource that represents Google Cloud Platform location.
        String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
        Builder gcsSource = ImportProductSetsGcsSource.newBuilder().setCsvFileUri(gcsUri);
        // Set the input configuration along with Google Cloud Storage URI
        ImportProductSetsInputConfig inputConfig = ImportProductSetsInputConfig.newBuilder().setGcsSource(gcsSource).build();
        // Import the product sets from the input URI.
        OperationFuture<ImportProductSetsResponse, BatchOperationMetadata> response = client.importProductSetsAsync(formattedParent, inputConfig);
        System.out.println(String.format("Processing operation name: %s", response.getName()));
        ImportProductSetsResponse results = response.get();
        System.out.println("Processing done.");
        System.out.println("Results of the processing:");
        for (int i = 0; i < results.getStatusesCount(); i++) {
            System.out.println(String.format("Status of processing line %s of the csv: %s", i, results.getStatuses(i)));
            // Check the status of reference image.
            if (results.getStatuses(i).getCode() == 0) {
                ReferenceImage referenceImage = results.getReferenceImages(i);
                System.out.println(referenceImage);
            } else {
                System.out.println("No reference image.");
            }
        }
    }
}
Also used : ImportProductSetsResponse(com.google.cloud.vision.v1.ImportProductSetsResponse) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Builder(com.google.cloud.vision.v1.ImportProductSetsGcsSource.Builder) BatchOperationMetadata(com.google.cloud.vision.v1.BatchOperationMetadata) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) ImportProductSetsInputConfig(com.google.cloud.vision.v1.ImportProductSetsInputConfig)

Example 8 with ReferenceImage

use of com.google.cloud.vision.v1.ReferenceImage 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 9 with ReferenceImage

use of com.google.cloud.vision.v1.ReferenceImage 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)

Aggregations

ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)7 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)4 Test (org.junit.Test)4 ListReferenceImagesPagedResponse (com.google.cloud.vision.v1.ProductSearchClient.ListReferenceImagesPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 AddProductToProductSetRequest (com.google.cloud.vision.v1.AddProductToProductSetRequest)1 BatchOperationMetadata (com.google.cloud.vision.v1.BatchOperationMetadata)1 CreateProductRequest (com.google.cloud.vision.v1.CreateProductRequest)1 CreateProductSetRequest (com.google.cloud.vision.v1.CreateProductSetRequest)1 CreateReferenceImageRequest (com.google.cloud.vision.v1.CreateReferenceImageRequest)1 GetReferenceImageRequest (com.google.cloud.vision.v1.GetReferenceImageRequest)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 ListReferenceImagesRequest (com.google.cloud.vision.v1.ListReferenceImagesRequest)1 Product (com.google.cloud.vision.v1.Product)1 ProductSet (com.google.cloud.vision.v1.ProductSet)1 BeforeClass (org.junit.BeforeClass)1