I am trying to use the @google-cloud/vision package to send requests to the Google Vision API. Is there a way to do multiple detections without doing something like:
client
.labelDetection(link)
.then(...)
client
.safeSearchDetection(link)
.then(...)
Thanks!
The @google-cloud/vision
package that you are using (or at least the latest version available as of writing, which is 0.19.x
) offers a variety of methods, each of which performs a different type of operation.
In your question, you refer to the methods labelDetection
and safeSearchDetection
. These are specific methods that perform the label detection and the Safe Search detection implementations of the Cloud Vision API, respectively.
Instead of using those feature-specific methods, you are interested in using annotateImage
instead, which annotates a single image with the features that you specify in the request.feature
parameter. This parameter is an array object that can include as many features as you want.
Below there is a sample code that would perform Label Detection and Safe Search Detection over a single image in a single call:
const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
const request = {
image: {source: {imageUri: 'gs://your/GCS/image.jpg'}},
features: [{type: vision.types.Feature.Type.LABEL_DETECTION}, {type: vision.types.Feature.Type.SAFE_SEARCH_DETECTION}],
};
client
.annotateImage(request)
.then(...);
Finally, here you have the list of available feature types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With