Search in sources :

Example 1 with ReferenceImage

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

the class ITSystemTest method getReferenceImageTest.

@Test
public void getReferenceImageTest() {
    GetReferenceImageRequest request = GetReferenceImageRequest.newBuilder().setName(formatReferenceImageName).build();
    ReferenceImage actualReferenceImage = productSearchClient.getReferenceImage(request);
    assertEquals(referenceImage.getName(), actualReferenceImage.getName());
    assertEquals(referenceImage.getUri(), actualReferenceImage.getUri());
}
Also used : GetReferenceImageRequest(com.google.cloud.vision.v1.GetReferenceImageRequest) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) Test(org.junit.Test)

Example 2 with ReferenceImage

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

the class ProductSearchClientTest method listReferenceImagesTest.

@Test
public void listReferenceImagesTest() throws Exception {
    ReferenceImage responsesElement = ReferenceImage.newBuilder().build();
    ListReferenceImagesResponse expectedResponse = ListReferenceImagesResponse.newBuilder().setNextPageToken("").addAllReferenceImages(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    ProductName parent = ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]");
    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.toString(), 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 3 with ReferenceImage

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

the class ReferenceImageManagement method listReferenceImagesOfProduct.

// [END vision_product_search_create_reference_image]
// [START vision_product_search_list_reference_images]
/**
 * List all images in a product.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @throws IOException - on I/O errors.
 */
public static void listReferenceImagesOfProduct(String projectId, String computeRegion, String productId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedParent = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        for (ReferenceImage image : client.listReferenceImages(formattedParent).iterateAll()) {
            // 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 4 with ReferenceImage

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

the class ITSystemTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    imageAnnotatorClient = ImageAnnotatorClient.create();
    /* create product */
    productSearchClient = ProductSearchClient.create();
    Product createProduct = Product.newBuilder().setName(PRODUCT_ID).setDisplayName(PRODUCT_DISPLAY_NAME).setProductCategory(PRODUCT_CATEGORY).build();
    CreateProductRequest productRequest = CreateProductRequest.newBuilder().setParent(LOCATION_NAME).setProduct(createProduct).build();
    product = productSearchClient.createProduct(productRequest);
    productName = getName(product.getName());
    formatProductName = ProductName.of(PROJECT_ID, COMPUTE_REGION, productName).toString();
    /* create product set */
    ProductSet createProductSet = ProductSet.newBuilder().setDisplayName(PRODUCT_SET_DISPLAY_NAME).build();
    CreateProductSetRequest productSetRequest = CreateProductSetRequest.newBuilder().setParent(LOCATION_NAME).setProductSet(createProductSet).setProductSetId(PRODUCT_SET_ID).build();
    productSet = productSearchClient.createProductSet(productSetRequest);
    productSetName = getName(productSet.getName());
    formatProductSetName = ProductSetName.of(PROJECT_ID, COMPUTE_REGION, productSetName).toString();
    /* add product to product set */
    AddProductToProductSetRequest productToProductSetRequest = AddProductToProductSetRequest.newBuilder().setName(formatProductSetName).setProduct(formatProductName).build();
    productSearchClient.addProductToProductSet(productToProductSetRequest);
    /* create reference image */
    ReferenceImage createReferenceImage = ReferenceImage.newBuilder().setUri(SAMPLE_BUCKET + "product_search/shoes_1.jpg").build();
    CreateReferenceImageRequest imageRequest = CreateReferenceImageRequest.newBuilder().setParent(formatProductName).setReferenceImage(createReferenceImage).build();
    referenceImage = productSearchClient.createReferenceImage(imageRequest);
    referenceImageName = getName(referenceImage.getName());
    formatReferenceImageName = ReferenceImageName.of(PROJECT_ID, COMPUTE_REGION, productName, referenceImageName).toString();
}
Also used : CreateProductRequest(com.google.cloud.vision.v1.CreateProductRequest) CreateReferenceImageRequest(com.google.cloud.vision.v1.CreateReferenceImageRequest) Product(com.google.cloud.vision.v1.Product) CreateProductSetRequest(com.google.cloud.vision.v1.CreateProductSetRequest) ProductSet(com.google.cloud.vision.v1.ProductSet) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) AddProductToProductSetRequest(com.google.cloud.vision.v1.AddProductToProductSetRequest) BeforeClass(org.junit.BeforeClass)

Example 5 with ReferenceImage

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

the class ITSystemTest method listReferenceImagesTest.

@Test
public void listReferenceImagesTest() {
    ListReferenceImagesRequest request = ListReferenceImagesRequest.newBuilder().setParent(formatProductName).build();
    for (ReferenceImage actualReferenceImage : productSearchClient.listReferenceImages(request).iterateAll()) {
        assertEquals(referenceImage.getName(), actualReferenceImage.getName());
        assertEquals(referenceImage.getUri(), actualReferenceImage.getUri());
    }
}
Also used : ListReferenceImagesRequest(com.google.cloud.vision.v1.ListReferenceImagesRequest) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) Test(org.junit.Test)

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