Bidstrup
Bidstrup

Reputation: 1617

Google cloud vision api 10 Limit results (nodejs)

I have read that the result limits are set to 10 by default, but Im not sure where to change this in the tutorial code provided by google.

vision.webDetection({ source: { filename: fileName } })
  .then((results) => {
    const webDetection = results[0].webDetection;
    if (webDetection.fullMatchingImages.length) {
      console.log(`Full matches found: ${webDetection.fullMatchingImages.length}`);
      webDetection.fullMatchingImages.forEach((image) => {
        console.log(`  URL: ${image.url}`);
        console.log(`  Score: ${image.score}`);
      });
    }
  })
  .catch((err) => {
    console.error('ERROR:', err);
  });

https://cloud.google.com/vision/docs/detecting-web

Upvotes: 1

Views: 563

Answers (1)

aofdev
aofdev

Reputation: 1812

Try the following:

const bucketName = 'Bucket where the file resides, e.g. my-bucket';
const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
    source: {
        imageUri: `gs://${bucketName}/${fileName}`
    },
    features: [{
        maxResults: 10 // change this result
    }]
};
vision.webDetection(request)
    .then((results) => {
        const webDetection = results[0].webDetection;
        if (webDetection.fullMatchingImages.length) {
            console.log(`Full matches found: ${webDetection.fullMatchingImages.length}`);
            webDetection.fullMatchingImages.forEach((image) => {
                console.log(`  URL: ${image.url}`);
                console.log(`  Score: ${image.score}`);
            });
        }
    })
    .catch((err) => {
        console.error('ERROR:', err);
    });

Ref: maxResults

Upvotes: 1

Related Questions