Constructor

ImageAnnotatorClient

new ImageAnnotatorClient(options)

Construct an instance of ImageAnnotatorClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Values in options have the following properties:

Parameter

credentials

Optional

object

Credentials object.

credentials.client_email

Optional

string

credentials.private_key

Optional

string

email

Optional

string

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename

Optional

string

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port

Optional

number

The port on which to connect to the remote host.

projectId

Optional

string

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise

Optional

function()

Custom promise module to use instead of native Promises.

servicePath

Optional

string

The domain name of the API remote host.

Properties

port

static

The port for this API service.

scopes

static

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static

The DNS address for this API service.

Methods

asyncBatchAnnotateFiles

asyncBatchAnnotateFiles(request, options, callback) returns Promise

Run async image detection and annotation for a list of generic files (e.g. PDF) which may contain multiple pages and multiple images per page. Progress and results can be retrieved through the google.longrunning.Operations interface. Operation.metadata contains OperationMetadata (metadata). Operation.response contains AsyncBatchAnnotateFilesResponse (results).

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

requests

Array of Object

Individual async file annotation requests for this batch.

This object should have the same structure as AsyncAnnotateFileRequest

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is a gax.Operation object.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is a gax.Operation object. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const vision = require('@google-cloud/vision');

var client = new vision.v1p2beta1.ImageAnnotatorClient({
  // optional auth parameters.
});

var requests = [];

// Handle the operation using the promise pattern.
client.asyncBatchAnnotateFiles({requests: requests})
  .then(responses => {
    var operation = responses[0];
    var initialApiResponse = responses[1];

    // Operation#promise starts polling for the completion of the LRO.
    return operation.promise();
  })
  .then(responses => {
    // The final result of the operation.
    var result = responses[0];

    // The metadata value of the completed operation.
    var metadata = responses[1];

    // The response of the api call returning the complete operation.
    var finalApiResponse = responses[2];
  })
  .catch(err => {
    console.error(err);
  });

var requests = [];

// Handle the operation using the event emitter pattern.
client.asyncBatchAnnotateFiles({requests: requests})
  .then(responses => {
    var operation = responses[0];
    var initialApiResponse = responses[1];

    // Adding a listener for the "complete" event starts polling for the
    // completion of the operation.
    operation.on('complete', (result, metadata, finalApiResponse) => {
      // doSomethingWith(result);
    });

    // Adding a listener for the "progress" event causes the callback to be
    // called on any change in metadata when the operation is polled.
    operation.on('progress', (metadata, apiResponse) => {
      // doSomethingWith(metadata)
    });

    // Adding a listener for the "error" event handles any errors found during polling.
    operation.on('error', err => {
      // throw(err);
    });
  })
  .catch(err => {
    console.error(err);
  });

batchAnnotateImages

batchAnnotateImages(request, options, callback) returns Promise

Run image detection and annotation for a batch of images.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

requests

Array of Object

Individual image annotation requests for this batch.

This object should have the same structure as AnnotateImageRequest

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing BatchAnnotateImagesResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing BatchAnnotateImagesResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const vision = require('@google-cloud/vision');

var client = new vision.v1p2beta1.ImageAnnotatorClient({
  // optional auth parameters.
});

var requests = [];
client.batchAnnotateImages({requests: requests})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.