use of com.google.cloud.vision.v1.ProductSet 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();
}
use of com.google.cloud.vision.v1.ProductSet 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()));
}
}
Aggregations