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 usaing 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 above 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

annotateImage

annotateImage(request, callOptions, callback) returns Promise

Annotate a single image with the requested features.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

features

Array of object

An array of the specific annotation features being requested. This should take a form such as:

    [{type: vision.types.Feature.Type.FACE_DETECTION},
    {type: vision.types.Feature.Type.WEB_DETECTION}]

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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');
const client = new vision.ImageAnnotatorClient();

const request = {
  image: {source: {imageUri: 'gs://path/to/image.jpg'}},
  features: [],
};
client
  .annotateImage(request)
  .then(response => {
    // doThingsWith(response);
  })
  .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.v1.ImageAnnotatorClient({
  // optional auth parameters.
});

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

cropHints

cropHints(request, callOptions, callback) returns Promise

Annotate a single image with crop hints.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.cropHints(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

documentTextDetection

documentTextDetection(request, callOptions, callback) returns Promise

Annotate a single image with document text detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.documentTextDetection(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

faceDetection

faceDetection(request, callOptions, callback) returns Promise

Annotate a single image with face detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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');
const client = new vision.ImageAnnotatorClient();

const request = {
  image: {
    source: {imageUri: 'gs://path/to/image.jpg'}
  }
};

client
  .faceDetection(request)
  .then(response => {
    // 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.

imageProperties

imageProperties(request, callOptions, callback) returns Promise

Annotate a single image with image properties.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.imageProperties(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

labelDetection

labelDetection(request, callOptions, callback) returns Promise

Annotate a single image with label detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.labelDetection(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

landmarkDetection

landmarkDetection(request, callOptions, callback) returns Promise

Annotate a single image with landmark detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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');
const client = new vision.ImageAnnotatorClient();

const request = {
  image: {
    source: {imageUri: 'gs://path/to/image.jpg'}
  }
};

client
  .landmarkDetection(request)
  .then(response => {
    // doThingsWith(response);
  })
  .catch(err => {
    console.error(err);
  });

logoDetection

logoDetection(request, callOptions, callback) returns Promise

Annotate a single image with logo detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.logoDetection(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

safeSearchDetection

safeSearchDetection(request, callOptions, callback) returns Promise

Annotate a single image with safe search detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.safeSearchDetection(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

textDetection

textDetection(request, callOptions, callback) returns Promise

Annotate a single image with text detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.textDetection(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});

webDetection

webDetection(request, callOptions, callback) returns Promise

Annotate a single image with web detection.

Parameter

request

(object, string, or Buffer)

A representation of the request being sent to the Vision API. This is an AnnotateImageRequest. For simple cases, you may also send a string (the URL or filename of the image) or a buffer (the image itself).

Values in request have the following properties:

Parameter

image

object

A dictionary-like object representing the image. This should have a single key (source, content).

If the key is `source`, the value should be another object containing
`imageUri` or `filename` as a key and a string as a value.

If the key is `content`, the value should be a Buffer.

callOptions

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.
See also
v1.ImageAnnotatorClient#batchAnnotateImages
google.cloud.vision.v1.AnnotateImageRequest
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

var image = {
  source: {imageUri: 'gs://path/to/image.jpg'}
};
vision.webDetection(image).then(response => {
  // doThingsWith(response);
}).catch(err => {
  console.error(err);
});