Given a list of image urls I want to annotate each image, i.e. extract text from each image. For that, I want to use Google Cloud Vision API client library in Java. Here is my pseudocode:
List<String> imageUrls = ...; List<AnnotateImageRequest> requests = imageUrls.stream() .map(convertToRequest) .collect(Collectors::toList); BatchAnnotateImagesResponse batchResponse = imageAnnotatorClient.batchAnnotateImages(requests);
Now from batchResponse I can get a list of AnnotateImageResponse. The questions are, does the number of AnnotateImageResponse correspond to the number of requests? Does the order of responses correspond to the order of requests? Can I safely assume that by doing so
for (int i = 0 ; i < imageUrls.size(); i++) { var url = imageUrls.get(i); var annotations = batchResponse.getResponses(i).getTextAnnotationsList(); }
I will get annotations for the right image on each iteration of the for loop? This is something that is not clear to me from the documentation.
Hello,
Have you tried to use AsyncBatchAnnotateImages instead of batchAnnotateImages? As the response contains the context of each image mentioning the uri, eg:
"context": {
"uri": "gs://cloud-samples-data/vision/document_understanding/image1.png"
}
The responses should be in the order of the requests.
Hello Nasif,
AsyncBatchAnnotateImages doesn't fit to my usecase. If you say the responses should be in the order of the request, then I'll go for it with BatchAnnotateImagesResponse.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |