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()));
}
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.");
}
}
}
}
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()));
}
}
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()));
}
}
Aggregations