0
votes

I am trying to do a asyncBatchAnnotation() request to annotate a bunch of images using Google Cloud Vision API.

Here is a snippet of my code: My function to create a request for batching:

module.exports = createRequests

const LABEL_DETECTION = 'LABEL_DETECTION'
const WEB_DETECTION = 'WEB_DETECTION'

function createRequests(imageUris) {
  let resources = {
    requests: [], 
    outputConfig
  } 
  for (let i = 0; i < imageUris.length; i++) {
    let request = {
      image: {source: {imageUri: imageUris[i]}},
      features: [{type: LABEL_DETECTION}, {type: WEB_DETECTION}]
    }
    resources.requests.push(request)
  }
  console.log(resources)
  return resources
}

My function for making the request itself:

// Imports the Google Cloud Client Library
const vision = require('@google-cloud/vision')

// Creates a client
const client = new vision.ImageAnnotatorClient()

const getImageUrls = require('./get-image-urls.js')
const createRequests = require('./create-requests.js')
const BUCKET_NAME = 'creative-engine'

function detectLabelsFromImage() {
  return new Promise(async(resolve, reject) => {
    try {
      let imageUris = await getImageUrls(BUCKET_NAME)
      let resources = createRequests(imageUris)
      try {
        let responses = await client.asyncBatchAnnotateImages(resources)
        const imageResponses = responses[0].responses
        imageResponses.forEach(imageResponse => {
          console.log('LABELS: ')
          const labels = imageResponse.labelAnnotations
          labels.forEach(label => {
            console.log(`label: ${label.description} | score: ${label.score}`)
          });
          console.log('WEB ENTITIES: ')
          const webEntities = imageResponse.webDetection.webEntities
          webEntities.forEach(webEntity => {
            console.log(`label: ${webEntity.description} | score: ${webEntity.score}`)
          });
        })

      } catch (err) {
        console.error('ERROR: ', err)
      }
    } catch (e) {
      reject(e)
    }
  })
}

Here is the error I get:

ERROR: Error: 3 INVALID_ARGUMENT: OutputConfig is required.

When I look at the Google Documentation here it states I need to use Google Cloud Storage for the JSON output.

I don't want to create a billing account with my information for Google Cloud. Is there a way to do this where I write to a local JSON file?

Thank you for your help!

1

1 Answers

1
votes

As per the link you shared says, it is not possible to write a local JSON file using the Cloud Vision API. You must to use GCS to store the file.