1
|
4
|
// Copyright 2017 Google LLC
|
2
|
4
|
//
|
3
|
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
4
|
// you may not use this file except in compliance with the License.
|
5
|
4
|
// You may obtain a copy of the License at
|
6
|
4
|
//
|
7
|
4
|
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
4
|
//
|
9
|
4
|
// Unless required by applicable law or agreed to in writing, software
|
10
|
4
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
4
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
4
|
// See the License for the specific language governing permissions and
|
13
|
4
|
// limitations under the License.
|
14
|
4
|
//
|
15
|
4
|
// ** This file is automatically generated by gapic-generator-typescript. **
|
16
|
4
|
// ** https://github.com/googleapis/gapic-generator-typescript **
|
17
|
4
|
// ** All changes to this file may be overwritten. **
|
18
|
4
|
|
19
|
4
|
import * as fs from 'fs';
|
20
|
4
|
import * as is from 'is';
|
21
|
4
|
import {promisify} from '@google-cloud/promisify';
|
22
|
4
|
import * as gax from 'google-gax';
|
23
|
4
|
import * as protoTypes from '../protos/protos';
|
24
|
4
|
interface FeatureFunction {
|
25
|
4
|
(request: string | ImprovedRequest | Buffer): Promise<
|
26
|
4
|
[protoTypes.google.cloud.vision.v1.IAnnotateImageResponse]
|
27
|
4
|
>;
|
28
|
4
|
}
|
29
|
4
|
export interface FeaturesMethod {
|
30
|
4
|
annotateImage: FeatureFunction;
|
31
|
4
|
faceDetection: FeatureFunction;
|
32
|
4
|
landmarkDetection: FeatureFunction;
|
33
|
4
|
labelDetection: FeatureFunction;
|
34
|
4
|
safeSearchDetection: FeatureFunction;
|
35
|
4
|
imageProperties: FeatureFunction;
|
36
|
4
|
cropHints: FeatureFunction;
|
37
|
4
|
webDetection: FeatureFunction;
|
38
|
4
|
logoDetection: FeatureFunction;
|
39
|
4
|
textDetection: FeatureFunction;
|
40
|
4
|
documentTextDetection: FeatureFunction;
|
41
|
4
|
productSearch?: FeatureFunction;
|
42
|
4
|
objectLocalization?: FeatureFunction;
|
43
|
4
|
}
|
44
|
4
|
interface ImprovedRequest {
|
45
|
4
|
image?: {
|
46
|
4
|
source?: {
|
47
|
4
|
filename?: string;
|
48
|
4
|
imageUri?: string;
|
49
|
4
|
};
|
50
|
4
|
content?: Uint8Array | string | null;
|
51
|
4
|
};
|
52
|
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
53
|
4
|
features?: any;
|
54
|
4
|
}
|
55
|
4
|
|
56
|
4
|
interface VisionClient {
|
57
|
4
|
batchAnnotateImages(
|
58
|
4
|
request: protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
|
59
|
4
|
options?: gax.CallOptions
|
60
|
4
|
): Promise<
|
61
|
4
|
[
|
62
|
4
|
protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
|
63
|
4
|
protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest | undefined,
|
64
|
4
|
{} | undefined
|
65
|
4
|
]
|
66
|
4
|
>;
|
67
|
4
|
batchAnnotateImages(
|
68
|
4
|
request: protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
|
69
|
4
|
options?: gax.CallOptions,
|
70
|
4
|
callback?: gax.Callback<
|
71
|
4
|
protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
|
72
|
4
|
protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest | undefined,
|
73
|
4
|
{} | undefined
|
74
|
4
|
>
|
75
|
4
|
): void;
|
76
|
4
|
annotateImage(
|
77
|
4
|
request: ImprovedRequest,
|
78
|
4
|
callOptions?: gax.CallOptions
|
79
|
4
|
): Promise<protoTypes.google.cloud.vision.v1.IAnnotateImageResponse>;
|
80
|
4
|
annotateImage(
|
81
|
4
|
request: ImprovedRequest,
|
82
|
4
|
callOptions: gax.CallOptions | undefined,
|
83
|
4
|
callback: gax.Callback<
|
84
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
85
|
4
|
{},
|
86
|
4
|
{}
|
87
|
4
|
>
|
88
|
4
|
): void;
|
89
|
4
|
}
|
90
|
4
|
|
91
|
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
92
|
4
|
const _requestToObject = (request: any) => {
|
93
|
4
|
if (is.string(request)) {
|
94
|
4
|
// Is this a URL or a local file?
|
95
|
4
|
// Guess based on what the string looks like, and build the full
|
96
|
4
|
// request object in the correct format.
|
97
|
4
|
if (request.indexOf('://') === -1 || request.indexOf('file://') === 0) {
|
98
|
4
|
request = ({
|
99
|
4
|
image: {source: {filename: request}},
|
100
|
4
|
} as unknown) as ImprovedRequest;
|
101
|
4
|
} else {
|
102
|
4
|
request = ({
|
103
|
4
|
image: {source: {imageUri: request}},
|
104
|
4
|
} as unknown) as ImprovedRequest;
|
105
|
4
|
}
|
106
|
4
|
} else if (Buffer.isBuffer(request)) {
|
107
|
4
|
// Drop the buffer one level lower; it will get dealt with later
|
108
|
4
|
// in the function. This allows sending <Buffer> and {image: <Buffer>} to
|
109
|
4
|
// both work identically.
|
110
|
4
|
request = ({image: request} as unknown) as ImprovedRequest;
|
111
|
4
|
}
|
112
|
4
|
return (request as unknown) as ImprovedRequest;
|
113
|
4
|
};
|
114
|
4
|
|
115
|
4
|
const _coerceRequest = (
|
116
|
4
|
request: ImprovedRequest,
|
117
|
4
|
callback: (
|
118
|
4
|
err: Error | null,
|
119
|
4
|
request?: protoTypes.google.cloud.vision.v1.IAnnotateImageRequest
|
120
|
4
|
) => void
|
121
|
4
|
) => {
|
122
|
4
|
// At this point, request must be an object with an `image` key; if not,
|
123
|
4
|
// it is an error. If there is no image, throw an exception.
|
124
|
4
|
if (!is.object(request) || is.undefined(request.image)) {
|
125
|
4
|
return callback(new Error('No image present.'));
|
126
|
4
|
}
|
127
|
4
|
// If this is a buffer, read it and send the object
|
128
|
4
|
// that the Vision API expects.
|
129
|
4
|
if (Buffer.isBuffer(request.image)) {
|
130
|
4
|
request.image = {content: request.image.toString('base64')};
|
131
|
4
|
}
|
132
|
4
|
|
133
|
4
|
// If the file is specified as a filename and exists on disk, read it
|
134
|
4
|
// and coerce it into the base64 content.
|
135
|
4
|
if (request.image!.source && request.image!.source.filename) {
|
136
|
4
|
fs.readFile(request.image!.source.filename, (err, blob) => {
|
137
|
4
|
if (err) {
|
138
|
4
|
callback(err);
|
139
|
4
|
return;
|
140
|
4
|
}
|
141
|
4
|
request.image!.content = blob.toString('base64');
|
142
|
4
|
delete request.image!.source;
|
143
|
4
|
return callback(
|
144
|
4
|
null,
|
145
|
4
|
request as protoTypes.google.cloud.vision.v1.IAnnotateImageRequest
|
146
|
4
|
);
|
147
|
4
|
});
|
148
|
4
|
} else {
|
149
|
4
|
return callback(
|
150
|
4
|
null,
|
151
|
4
|
request as protoTypes.google.cloud.vision.v1.IAnnotateImageRequest
|
152
|
4
|
);
|
153
|
4
|
}
|
154
|
4
|
};
|
155
|
4
|
|
156
|
4
|
const _createSingleFeatureMethod = (
|
157
|
4
|
featureValue: protoTypes.google.cloud.vision.v1.Feature.Type
|
158
|
4
|
) => {
|
159
|
4
|
return function (
|
160
|
4
|
this: VisionClient,
|
161
|
4
|
request: string,
|
162
|
4
|
callOptionsOrCallback?:
|
163
|
4
|
| gax.CallOptions
|
164
|
4
|
| gax.Callback<
|
165
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
166
|
4
|
{},
|
167
|
4
|
{}
|
168
|
4
|
>,
|
169
|
4
|
callback?: gax.Callback<
|
170
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
171
|
4
|
{},
|
172
|
4
|
{}
|
173
|
4
|
>
|
174
|
4
|
) {
|
175
|
4
|
// Sanity check: If we got a string or buffer, we need this to be
|
176
|
4
|
// in object form now, so we can tack on the features list.
|
177
|
4
|
//
|
178
|
4
|
// Do the minimum required conversion, which can also be guaranteed to
|
179
|
4
|
// be synchronous (e.g. no file loading yet; that is handled by
|
180
|
4
|
// annotateImage later.
|
181
|
4
|
const annotateImageRequest: ImprovedRequest = _requestToObject(request);
|
182
|
4
|
// If a callback was provided and options were skipped, normalize
|
183
|
4
|
// the argument names.
|
184
|
4
|
let callOptions: gax.CallOptions | undefined;
|
185
|
4
|
if (is.undefined(callback) && is.function(callOptionsOrCallback)) {
|
186
|
4
|
callback = callOptionsOrCallback as gax.Callback<
|
187
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
188
|
4
|
{},
|
189
|
4
|
{}
|
190
|
4
|
>;
|
191
|
4
|
callOptions = undefined;
|
192
|
4
|
} else {
|
193
|
4
|
callOptions = callOptionsOrCallback as gax.CallOptions | undefined;
|
194
|
4
|
}
|
195
|
4
|
|
196
|
4
|
// Add the feature to the request.
|
197
|
4
|
annotateImageRequest.features = annotateImageRequest.features || [
|
198
|
4
|
{
|
199
|
4
|
type: featureValue,
|
200
|
4
|
},
|
201
|
4
|
];
|
202
|
4
|
|
203
|
4
|
// If the user submitted explicit features that do not line up with
|
204
|
4
|
// the precise method called, throw an exception.
|
205
|
4
|
for (const feature of annotateImageRequest.features) {
|
206
|
4
|
if (feature.type !== featureValue) {
|
207
|
4
|
throw new Error(
|
208
|
4
|
'Setting explicit features is not supported on this method. ' +
|
209
|
4
|
'Use the #annotateImage method instead.'
|
210
|
4
|
);
|
211
|
4
|
}
|
212
|
4
|
}
|
213
|
4
|
// Call the underlying #annotateImage method.
|
214
|
4
|
return this.annotateImage(annotateImageRequest, callOptions, callback!);
|
215
|
4
|
};
|
216
|
4
|
};
|
217
|
4
|
|
218
|
4
|
export function call(apiVersion: string) {
|
219
|
4
|
const methods: FeaturesMethod = ({} as unknown) as FeaturesMethod;
|
220
|
4
|
/**
|
221
|
4
|
* Annotate a single image with the requested features.
|
222
|
4
|
*
|
223
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
224
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
225
|
4
|
*
|
226
|
4
|
* @method v1.ImageAnnotatorClient#annotateImage
|
227
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
228
|
4
|
* being sent to the Vision API. This is an
|
229
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
230
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
231
|
4
|
* the image) or a buffer (the image itself).
|
232
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
233
|
4
|
* image. This should have a single key (`source`, `content`).
|
234
|
4
|
*
|
235
|
4
|
* If the key is `source`, the value should be another object containing
|
236
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
237
|
4
|
*
|
238
|
4
|
* If the key is `content`, the value should be a Buffer.
|
239
|
4
|
* @param {object[]} request.features An array of the specific annotation
|
240
|
4
|
* features being requested. This should take a form such as:
|
241
|
4
|
*
|
242
|
4
|
* [{type: vision.types.Feature.Type.FACE_DETECTION},
|
243
|
4
|
* {type: vision.types.Feature.Type.WEB_DETECTION}]
|
244
|
4
|
*
|
245
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
246
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
247
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
248
|
4
|
* for the details.
|
249
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
250
|
4
|
* called with the result of the API call.
|
251
|
4
|
*
|
252
|
4
|
* The second parameter to the callback is an object representing
|
253
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
254
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
255
|
4
|
* element of the array is an object representing
|
256
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
257
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
258
|
4
|
* call.
|
259
|
4
|
*
|
260
|
4
|
* @example
|
261
|
4
|
* const vision = require('@google-cloud/vision');
|
262
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
263
|
4
|
*
|
264
|
4
|
* const request = {
|
265
|
4
|
* image: {source: {imageUri: 'gs://path/to/image.jpg'}},
|
266
|
4
|
* features: [],
|
267
|
4
|
* };
|
268
|
4
|
* client
|
269
|
4
|
* .annotateImage(request)
|
270
|
4
|
* .then(response => {
|
271
|
4
|
* // doThingsWith(response);
|
272
|
4
|
* })
|
273
|
4
|
* .catch(err => {
|
274
|
4
|
* console.error(err);
|
275
|
4
|
* });
|
276
|
4
|
*/
|
277
|
4
|
|
278
|
4
|
methods.annotateImage = promisify(function (
|
279
|
4
|
this: VisionClient,
|
280
|
4
|
request: ImprovedRequest,
|
281
|
4
|
callOptionsOrCallback:
|
282
|
4
|
| gax.Callback<
|
283
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
284
|
4
|
{},
|
285
|
4
|
{}
|
286
|
4
|
>
|
287
|
4
|
| gax.CallOptions,
|
288
|
4
|
callback?: gax.Callback<
|
289
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
290
|
4
|
{},
|
291
|
4
|
{}
|
292
|
4
|
>
|
293
|
4
|
) {
|
294
|
4
|
// If a callback was provided and options were skipped, normalize
|
295
|
4
|
// the argument names.
|
296
|
4
|
let callOptions: gax.CallOptions | undefined;
|
297
|
4
|
if (is.undefined(callback) && is.function(callOptionsOrCallback)) {
|
298
|
4
|
callback = callOptionsOrCallback as gax.Callback<
|
299
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
300
|
4
|
{},
|
301
|
4
|
{}
|
302
|
4
|
>;
|
303
|
4
|
callOptions = undefined;
|
304
|
4
|
} else {
|
305
|
4
|
callOptions = callOptionsOrCallback as gax.CallOptions | undefined;
|
306
|
4
|
}
|
307
|
4
|
|
308
|
4
|
// If we got a filename for the image, open the file and transform
|
309
|
4
|
// it to content.
|
310
|
4
|
return _coerceRequest(
|
311
|
4
|
request,
|
312
|
4
|
(
|
313
|
4
|
err: Error | null,
|
314
|
4
|
req: protoTypes.google.cloud.vision.v1.IAnnotateImageRequest | undefined
|
315
|
4
|
) => {
|
316
|
4
|
if (err) {
|
317
|
4
|
return ((callback as unknown) as gax.Callback<
|
318
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
319
|
4
|
{},
|
320
|
4
|
{}
|
321
|
4
|
>)(err);
|
322
|
4
|
}
|
323
|
4
|
|
324
|
4
|
// Call the GAPIC batch annotation function.
|
325
|
4
|
const requests = {requests: [req!]};
|
326
|
4
|
return this.batchAnnotateImages(
|
327
|
4
|
requests,
|
328
|
4
|
callOptions,
|
329
|
4
|
(
|
330
|
4
|
err: Error | null | undefined,
|
331
|
4
|
r:
|
332
|
4
|
| protoTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse
|
333
|
4
|
| null
|
334
|
4
|
| undefined
|
335
|
4
|
) => {
|
336
|
4
|
// If there is an error, handle it.
|
337
|
4
|
if (err) {
|
338
|
4
|
return ((callback as unknown) as gax.Callback<
|
339
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
340
|
4
|
{},
|
341
|
4
|
{}
|
342
|
4
|
>)(err);
|
343
|
4
|
}
|
344
|
4
|
|
345
|
4
|
// We are guaranteed to only have one response element, since we
|
346
|
4
|
// only sent one image.
|
347
|
4
|
const response = r!.responses![0];
|
348
|
4
|
|
349
|
4
|
// Fire the callback if applicable.
|
350
|
4
|
return ((callback as unknown) as gax.Callback<
|
351
|
4
|
protoTypes.google.cloud.vision.v1.IAnnotateImageResponse,
|
352
|
4
|
{},
|
353
|
4
|
{}
|
354
|
4
|
>)(undefined, response);
|
355
|
4
|
}
|
356
|
4
|
);
|
357
|
4
|
}
|
358
|
4
|
);
|
359
|
4
|
});
|
360
|
4
|
|
361
|
4
|
const protoFilesRoot = gax.protobuf.Root.fromJSON(
|
362
|
4
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
363
|
4
|
require('../protos/protos.json')
|
364
|
4
|
);
|
365
|
4
|
const features = (protoFilesRoot.lookup(
|
366
|
4
|
`google.cloud.vision.${apiVersion}.Feature.Type`
|
367
|
4
|
) as gax.protobuf.Enum).values;
|
368
|
4
|
|
369
|
4
|
/**
|
370
|
4
|
* Annotate a single image with face detection.
|
371
|
4
|
*
|
372
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
373
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
374
|
4
|
*
|
375
|
4
|
* @method v1.ImageAnnotatorClient#faceDetection
|
376
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
377
|
4
|
* being sent to the Vision API. This is an
|
378
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
379
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
380
|
4
|
* the image) or a buffer (the image itself).
|
381
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
382
|
4
|
* image. This should have a single key (`source`, `content`).
|
383
|
4
|
*
|
384
|
4
|
* If the key is `source`, the value should be another object containing
|
385
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
386
|
4
|
*
|
387
|
4
|
* If the key is `content`, the value should be a Buffer.
|
388
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
389
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
390
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
391
|
4
|
* for the details.
|
392
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
393
|
4
|
* called with the result of the API call.
|
394
|
4
|
*
|
395
|
4
|
* The second parameter to the callback is an object representing
|
396
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
397
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
398
|
4
|
* element of the array is an object representing
|
399
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
400
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
401
|
4
|
* call.
|
402
|
4
|
*
|
403
|
4
|
* @example
|
404
|
4
|
* const vision = require('@google-cloud/vision');
|
405
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
406
|
4
|
*
|
407
|
4
|
* const request = {
|
408
|
4
|
* image: {
|
409
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
410
|
4
|
* }
|
411
|
4
|
* };
|
412
|
4
|
*
|
413
|
4
|
* client
|
414
|
4
|
* .faceDetection(request)
|
415
|
4
|
* .then(response => {
|
416
|
4
|
* // doThingsWith(response);
|
417
|
4
|
* })
|
418
|
4
|
* .catch(err => {
|
419
|
4
|
* console.error(err);
|
420
|
4
|
* });
|
421
|
4
|
*/
|
422
|
4
|
|
423
|
4
|
methods.faceDetection = promisify(
|
424
|
4
|
_createSingleFeatureMethod(features!.FACE_DETECTION)
|
425
|
4
|
);
|
426
|
4
|
/**
|
427
|
4
|
* Annotate a single image with landmark detection.
|
428
|
4
|
*
|
429
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
430
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
431
|
4
|
*
|
432
|
4
|
* @method v1.ImageAnnotatorClient#landmarkDetection
|
433
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
434
|
4
|
* being sent to the Vision API. This is an
|
435
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
436
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
437
|
4
|
* the image) or a buffer (the image itself).
|
438
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
439
|
4
|
* image. This should have a single key (`source`, `content`).
|
440
|
4
|
*
|
441
|
4
|
* If the key is `source`, the value should be another object containing
|
442
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
443
|
4
|
*
|
444
|
4
|
* If the key is `content`, the value should be a Buffer.
|
445
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
446
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
447
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
448
|
4
|
* for the details.
|
449
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
450
|
4
|
* called with the result of the API call.
|
451
|
4
|
*
|
452
|
4
|
* The second parameter to the callback is an object representing
|
453
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
454
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
455
|
4
|
* element of the array is an object representing
|
456
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
457
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
458
|
4
|
* call.
|
459
|
4
|
*
|
460
|
4
|
* @example
|
461
|
4
|
* const vision = require('@google-cloud/vision');
|
462
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
463
|
4
|
*
|
464
|
4
|
* const request = {
|
465
|
4
|
* image: {
|
466
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
467
|
4
|
* }
|
468
|
4
|
* };
|
469
|
4
|
*
|
470
|
4
|
* client
|
471
|
4
|
* .landmarkDetection(request)
|
472
|
4
|
* .then(response => {
|
473
|
4
|
* // doThingsWith(response);
|
474
|
4
|
* })
|
475
|
4
|
* .catch(err => {
|
476
|
4
|
* console.error(err);
|
477
|
4
|
* });
|
478
|
4
|
*/
|
479
|
4
|
|
480
|
4
|
methods.landmarkDetection = promisify(
|
481
|
4
|
_createSingleFeatureMethod(features!.LANDMARK_DETECTION)
|
482
|
4
|
);
|
483
|
4
|
/**
|
484
|
4
|
* Annotate a single image with logo detection.
|
485
|
4
|
*
|
486
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
487
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
488
|
4
|
*
|
489
|
4
|
* @method v1.ImageAnnotatorClient#logoDetection
|
490
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
491
|
4
|
* being sent to the Vision API. This is an
|
492
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
493
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
494
|
4
|
* the image) or a buffer (the image itself).
|
495
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
496
|
4
|
* image. This should have a single key (`source`, `content`).
|
497
|
4
|
*
|
498
|
4
|
* If the key is `source`, the value should be another object containing
|
499
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
500
|
4
|
*
|
501
|
4
|
* If the key is `content`, the value should be a Buffer.
|
502
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
503
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
504
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
505
|
4
|
* for the details.
|
506
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
507
|
4
|
* called with the result of the API call.
|
508
|
4
|
*
|
509
|
4
|
* The second parameter to the callback is an object representing
|
510
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
511
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
512
|
4
|
* element of the array is an object representing
|
513
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
514
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
515
|
4
|
* call.
|
516
|
4
|
*
|
517
|
4
|
* @example
|
518
|
4
|
* const vision = require('@google-cloud/vision');
|
519
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
520
|
4
|
*
|
521
|
4
|
* const request = {
|
522
|
4
|
* image: {
|
523
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
524
|
4
|
* }
|
525
|
4
|
* };
|
526
|
4
|
*
|
527
|
4
|
* client
|
528
|
4
|
* .logoDetection(request)
|
529
|
4
|
* .then(response => {
|
530
|
4
|
* // doThingsWith(response);
|
531
|
4
|
* })
|
532
|
4
|
* .catch(err => {
|
533
|
4
|
* console.error(err);
|
534
|
4
|
* });
|
535
|
4
|
*/
|
536
|
4
|
|
537
|
4
|
methods.logoDetection = promisify(
|
538
|
4
|
_createSingleFeatureMethod(features.LOGO_DETECTION)
|
539
|
4
|
);
|
540
|
4
|
/**
|
541
|
4
|
* Annotate a single image with label detection.
|
542
|
4
|
*
|
543
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
544
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
545
|
4
|
*
|
546
|
4
|
* @method v1.ImageAnnotatorClient#labelDetection
|
547
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
548
|
4
|
* being sent to the Vision API. This is an
|
549
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
550
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
551
|
4
|
* the image) or a buffer (the image itself).
|
552
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
553
|
4
|
* image. This should have a single key (`source`, `content`).
|
554
|
4
|
*
|
555
|
4
|
* If the key is `source`, the value should be another object containing
|
556
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
557
|
4
|
*
|
558
|
4
|
* If the key is `content`, the value should be a Buffer.
|
559
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
560
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
561
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
562
|
4
|
* for the details.
|
563
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
564
|
4
|
* called with the result of the API call.
|
565
|
4
|
*
|
566
|
4
|
* The second parameter to the callback is an object representing
|
567
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
568
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
569
|
4
|
* element of the array is an object representing
|
570
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
571
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
572
|
4
|
* call.
|
573
|
4
|
*
|
574
|
4
|
* @example
|
575
|
4
|
* const vision = require('@google-cloud/vision');
|
576
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
577
|
4
|
*
|
578
|
4
|
* const request = {
|
579
|
4
|
* image: {
|
580
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
581
|
4
|
* }
|
582
|
4
|
* };
|
583
|
4
|
*
|
584
|
4
|
* client
|
585
|
4
|
* .labelDetection(request)
|
586
|
4
|
* .then(response => {
|
587
|
4
|
* // doThingsWith(response);
|
588
|
4
|
* })
|
589
|
4
|
* .catch(err => {
|
590
|
4
|
* console.error(err);
|
591
|
4
|
* });
|
592
|
4
|
*/
|
593
|
4
|
|
594
|
4
|
methods.labelDetection = promisify(
|
595
|
4
|
_createSingleFeatureMethod(features!.LABEL_DETECTION)
|
596
|
4
|
);
|
597
|
4
|
/**
|
598
|
4
|
* Annotate a single image with text detection.
|
599
|
4
|
*
|
600
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
601
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
602
|
4
|
*
|
603
|
4
|
* @method v1.ImageAnnotatorClient#textDetection
|
604
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
605
|
4
|
* being sent to the Vision API. This is an
|
606
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
607
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
608
|
4
|
* the image) or a buffer (the image itself).
|
609
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
610
|
4
|
* image. This should have a single key (`source`, `content`).
|
611
|
4
|
*
|
612
|
4
|
* If the key is `source`, the value should be another object containing
|
613
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
614
|
4
|
*
|
615
|
4
|
* If the key is `content`, the value should be a Buffer.
|
616
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
617
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
618
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
619
|
4
|
* for the details.
|
620
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
621
|
4
|
* called with the result of the API call.
|
622
|
4
|
*
|
623
|
4
|
* The second parameter to the callback is an object representing
|
624
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
625
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
626
|
4
|
* element of the array is an object representing
|
627
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
628
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
629
|
4
|
* call.
|
630
|
4
|
*
|
631
|
4
|
* @example
|
632
|
4
|
* const vision = require('@google-cloud/vision');
|
633
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
634
|
4
|
*
|
635
|
4
|
* const request = {
|
636
|
4
|
* image: {
|
637
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
638
|
4
|
* }
|
639
|
4
|
* };
|
640
|
4
|
*
|
641
|
4
|
* client
|
642
|
4
|
* .textDetection(request)
|
643
|
4
|
* .then(response => {
|
644
|
4
|
* // doThingsWith(response);
|
645
|
4
|
* })
|
646
|
4
|
* .catch(err => {
|
647
|
4
|
* console.error(err);
|
648
|
4
|
* });
|
649
|
4
|
*/
|
650
|
4
|
|
651
|
4
|
methods.textDetection = promisify(
|
652
|
4
|
_createSingleFeatureMethod(features.TEXT_DETECTION)
|
653
|
4
|
);
|
654
|
4
|
/**
|
655
|
4
|
* Annotate a single image with document text detection.
|
656
|
4
|
*
|
657
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
658
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
659
|
4
|
*
|
660
|
4
|
* @method v1.ImageAnnotatorClient#documentTextDetection
|
661
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
662
|
4
|
* being sent to the Vision API. This is an
|
663
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
664
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
665
|
4
|
* the image) or a buffer (the image itself).
|
666
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
667
|
4
|
* image. This should have a single key (`source`, `content`).
|
668
|
4
|
*
|
669
|
4
|
* If the key is `source`, the value should be another object containing
|
670
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
671
|
4
|
*
|
672
|
4
|
* If the key is `content`, the value should be a Buffer.
|
673
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
674
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
675
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
676
|
4
|
* for the details.
|
677
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
678
|
4
|
* called with the result of the API call.
|
679
|
4
|
*
|
680
|
4
|
* The second parameter to the callback is an object representing
|
681
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
682
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
683
|
4
|
* element of the array is an object representing
|
684
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
685
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
686
|
4
|
* call.
|
687
|
4
|
*
|
688
|
4
|
* @example
|
689
|
4
|
* const vision = require('@google-cloud/vision');
|
690
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
691
|
4
|
*
|
692
|
4
|
* const request = {
|
693
|
4
|
* image: {
|
694
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
695
|
4
|
* }
|
696
|
4
|
* };
|
697
|
4
|
*
|
698
|
4
|
* client
|
699
|
4
|
* .documentTextDetection(request)
|
700
|
4
|
* .then(response => {
|
701
|
4
|
* // doThingsWith(response);
|
702
|
4
|
* })
|
703
|
4
|
* .catch(err => {
|
704
|
4
|
* console.error(err);
|
705
|
4
|
* });
|
706
|
4
|
*/
|
707
|
4
|
|
708
|
4
|
methods.documentTextDetection = promisify(
|
709
|
4
|
_createSingleFeatureMethod(features.DOCUMENT_TEXT_DETECTION)
|
710
|
4
|
);
|
711
|
4
|
/**
|
712
|
4
|
* Annotate a single image with safe search detection.
|
713
|
4
|
*
|
714
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
715
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
716
|
4
|
*
|
717
|
4
|
* @method v1.ImageAnnotatorClient#safeSearchDetection
|
718
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
719
|
4
|
* being sent to the Vision API. This is an
|
720
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
721
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
722
|
4
|
* the image) or a buffer (the image itself).
|
723
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
724
|
4
|
* image. This should have a single key (`source`, `content`).
|
725
|
4
|
*
|
726
|
4
|
* If the key is `source`, the value should be another object containing
|
727
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
728
|
4
|
*
|
729
|
4
|
* If the key is `content`, the value should be a Buffer.
|
730
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
731
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
732
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
733
|
4
|
* for the details.
|
734
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
735
|
4
|
* called with the result of the API call.
|
736
|
4
|
*
|
737
|
4
|
* The second parameter to the callback is an object representing
|
738
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
739
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
740
|
4
|
* element of the array is an object representing
|
741
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
742
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
743
|
4
|
* call.
|
744
|
4
|
*
|
745
|
4
|
* @example
|
746
|
4
|
* const vision = require('@google-cloud/vision');
|
747
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
748
|
4
|
*
|
749
|
4
|
* const request = {
|
750
|
4
|
* image: {
|
751
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
752
|
4
|
* }
|
753
|
4
|
* };
|
754
|
4
|
*
|
755
|
4
|
* client
|
756
|
4
|
* .safeSearchDetection(request)
|
757
|
4
|
* .then(response => {
|
758
|
4
|
* // doThingsWith(response);
|
759
|
4
|
* })
|
760
|
4
|
* .catch(err => {
|
761
|
4
|
* console.error(err);
|
762
|
4
|
* });
|
763
|
4
|
*/
|
764
|
4
|
|
765
|
4
|
methods.safeSearchDetection = promisify(
|
766
|
4
|
_createSingleFeatureMethod(features!.SAFE_SEARCH_DETECTION)
|
767
|
4
|
);
|
768
|
4
|
/**
|
769
|
4
|
* Annotate a single image with image properties.
|
770
|
4
|
*
|
771
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
772
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
773
|
4
|
*
|
774
|
4
|
* @method v1.ImageAnnotatorClient#imageProperties
|
775
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
776
|
4
|
* being sent to the Vision API. This is an
|
777
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
778
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
779
|
4
|
* the image) or a buffer (the image itself).
|
780
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
781
|
4
|
* image. This should have a single key (`source`, `content`).
|
782
|
4
|
*
|
783
|
4
|
* If the key is `source`, the value should be another object containing
|
784
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
785
|
4
|
*
|
786
|
4
|
* If the key is `content`, the value should be a Buffer.
|
787
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
788
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
789
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
790
|
4
|
* for the details.
|
791
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
792
|
4
|
* called with the result of the API call.
|
793
|
4
|
*
|
794
|
4
|
* The second parameter to the callback is an object representing
|
795
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
796
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
797
|
4
|
* element of the array is an object representing
|
798
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
799
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
800
|
4
|
* call.
|
801
|
4
|
*
|
802
|
4
|
* @example
|
803
|
4
|
* const vision = require('@google-cloud/vision');
|
804
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
805
|
4
|
*
|
806
|
4
|
* const request = {
|
807
|
4
|
* image: {
|
808
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
809
|
4
|
* }
|
810
|
4
|
* };
|
811
|
4
|
*
|
812
|
4
|
* client
|
813
|
4
|
* .imageProperties(request)
|
814
|
4
|
* .then(response => {
|
815
|
4
|
* // doThingsWith(response);
|
816
|
4
|
* })
|
817
|
4
|
* .catch(err => {
|
818
|
4
|
* console.error(err);
|
819
|
4
|
* });
|
820
|
4
|
*/
|
821
|
4
|
|
822
|
4
|
methods.imageProperties = promisify(
|
823
|
4
|
_createSingleFeatureMethod(features!.IMAGE_PROPERTIES)
|
824
|
4
|
);
|
825
|
4
|
/**
|
826
|
4
|
* Annotate a single image with crop hints.
|
827
|
4
|
*
|
828
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
829
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
830
|
4
|
*
|
831
|
4
|
* @method v1.ImageAnnotatorClient#cropHints
|
832
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
833
|
4
|
* being sent to the Vision API. This is an
|
834
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
835
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
836
|
4
|
* the image) or a buffer (the image itself).
|
837
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
838
|
4
|
* image. This should have a single key (`source`, `content`).
|
839
|
4
|
*
|
840
|
4
|
* If the key is `source`, the value should be another object containing
|
841
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
842
|
4
|
*
|
843
|
4
|
* If the key is `content`, the value should be a Buffer.
|
844
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
845
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
846
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
847
|
4
|
* for the details.
|
848
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
849
|
4
|
* called with the result of the API call.
|
850
|
4
|
*
|
851
|
4
|
* The second parameter to the callback is an object representing
|
852
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
853
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
854
|
4
|
* element of the array is an object representing
|
855
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
856
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
857
|
4
|
* call.
|
858
|
4
|
*
|
859
|
4
|
* @example
|
860
|
4
|
* const vision = require('@google-cloud/vision');
|
861
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
862
|
4
|
*
|
863
|
4
|
* const request = {
|
864
|
4
|
* image: {
|
865
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
866
|
4
|
* }
|
867
|
4
|
* };
|
868
|
4
|
*
|
869
|
4
|
* client
|
870
|
4
|
* .cropHints(request)
|
871
|
4
|
* .then(response => {
|
872
|
4
|
* // doThingsWith(response);
|
873
|
4
|
* })
|
874
|
4
|
* .catch(err => {
|
875
|
4
|
* console.error(err);
|
876
|
4
|
* });
|
877
|
4
|
*/
|
878
|
4
|
|
879
|
4
|
methods.cropHints = promisify(
|
880
|
4
|
_createSingleFeatureMethod(features!.CROP_HINTS)
|
881
|
4
|
);
|
882
|
4
|
/**
|
883
|
4
|
* Annotate a single image with web detection.
|
884
|
4
|
*
|
885
|
4
|
* @see v1.ImageAnnotatorClient#batchAnnotateImages
|
886
|
4
|
* @see google.cloud.vision.v1.AnnotateImageRequest
|
887
|
4
|
*
|
888
|
4
|
* @method v1.ImageAnnotatorClient#webDetection
|
889
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
890
|
4
|
* being sent to the Vision API. This is an
|
891
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
892
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
893
|
4
|
* the image) or a buffer (the image itself).
|
894
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
895
|
4
|
* image. This should have a single key (`source`, `content`).
|
896
|
4
|
*
|
897
|
4
|
* If the key is `source`, the value should be another object containing
|
898
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
899
|
4
|
*
|
900
|
4
|
* If the key is `content`, the value should be a Buffer.
|
901
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
902
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
903
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
904
|
4
|
* for the details.
|
905
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
906
|
4
|
* called with the result of the API call.
|
907
|
4
|
*
|
908
|
4
|
* The second parameter to the callback is an object representing
|
909
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
910
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
911
|
4
|
* element of the array is an object representing
|
912
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
913
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
914
|
4
|
* call.
|
915
|
4
|
*
|
916
|
4
|
* @example
|
917
|
4
|
* const vision = require('@google-cloud/vision');
|
918
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
919
|
4
|
*
|
920
|
4
|
* const request = {
|
921
|
4
|
* image: {
|
922
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
923
|
4
|
* }
|
924
|
4
|
* };
|
925
|
4
|
*
|
926
|
4
|
* client
|
927
|
4
|
* .webDetection(request)
|
928
|
4
|
* .then(response => {
|
929
|
4
|
* // doThingsWith(response);
|
930
|
4
|
* })
|
931
|
4
|
* .catch(err => {
|
932
|
4
|
* console.error(err);
|
933
|
4
|
* });
|
934
|
4
|
*/
|
935
|
4
|
|
936
|
4
|
methods.webDetection = promisify(
|
937
|
4
|
_createSingleFeatureMethod(features!.WEB_DETECTION)
|
938
|
4
|
);
|
939
|
4
|
/**
|
940
|
4
|
* Annotate a single image with the result from Product Search.
|
941
|
4
|
*
|
942
|
4
|
* @see v1p3beta1.ImageAnnotatorClient#batchAnnotateImages
|
943
|
4
|
* @see google.cloud.vision.v1p3beta1.AnnotateImageRequest
|
944
|
4
|
*
|
945
|
4
|
* @method v1p3beta1.ImageAnnotatorClient#productSearch
|
946
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
947
|
4
|
* being sent to the Vision API. This is an
|
948
|
4
|
* {@link google.cloud.vision.v1p3beta1.AnnotateImageRequest AnnotateImageRequest}.
|
949
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
950
|
4
|
* the image) or a buffer (the image itself).
|
951
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
952
|
4
|
* image. This should have a single key (`source`, `content`).
|
953
|
4
|
*
|
954
|
4
|
* If the key is `source`, the value should be another object containing
|
955
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
956
|
4
|
*
|
957
|
4
|
* If the key is `content`, the value should be a Buffer.
|
958
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
959
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
960
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
961
|
4
|
* called with the result of the API call.
|
962
|
4
|
*
|
963
|
4
|
* The second parameter to the callback is an object representing
|
964
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
965
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
966
|
4
|
* element of the array is an object representing
|
967
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
968
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
969
|
4
|
* call.
|
970
|
4
|
*
|
971
|
4
|
* @example
|
972
|
4
|
* const vision = require('@google-cloud/vision').v1p3beta1;
|
973
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
974
|
4
|
*
|
975
|
4
|
* const request = {
|
976
|
4
|
* image: {
|
977
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
978
|
4
|
* }
|
979
|
4
|
* };
|
980
|
4
|
*
|
981
|
4
|
* client
|
982
|
4
|
* .productSearch(request)
|
983
|
4
|
* .then(response => {
|
984
|
4
|
* // doThingsWith(response);
|
985
|
4
|
* })
|
986
|
4
|
* .catch(err => {
|
987
|
4
|
* console.error(err);
|
988
|
4
|
* });
|
989
|
4
|
*/
|
990
|
4
|
if (features!.PRODUCT_SEARCH !== undefined) {
|
991
|
4
|
methods.productSearch = promisify(
|
992
|
4
|
_createSingleFeatureMethod(features!.PRODUCT_SEARCH)
|
993
|
4
|
);
|
994
|
4
|
}
|
995
|
4
|
/**
|
996
|
4
|
* Annotate a single image with localization vectors.
|
997
|
4
|
*
|
998
|
4
|
* @see v1p3beta1.ImageAnnotatorClient#batchAnnotateImages
|
999
|
4
|
* @see google.cloud.vision.v1p3beta1.AnnotateImageRequest
|
1000
|
4
|
*
|
1001
|
4
|
* @method v1p3beta1.ImageAnnotatorClient#objectLocalization
|
1002
|
4
|
* @param {object|string|Buffer} request A representation of the request
|
1003
|
4
|
* being sent to the Vision API. This is an
|
1004
|
4
|
* {@link google.cloud.vision.v1.AnnotateImageRequest AnnotateImageRequest}.
|
1005
|
4
|
* For simple cases, you may also send a string (the URL or filename of
|
1006
|
4
|
* the image) or a buffer (the image itself).
|
1007
|
4
|
* @param {object} request.image A dictionary-like object representing the
|
1008
|
4
|
* image. This should have a single key (`source`, `content`).
|
1009
|
4
|
*
|
1010
|
4
|
* If the key is `source`, the value should be another object containing
|
1011
|
4
|
* `imageUri` or `filename` as a key and a string as a value.
|
1012
|
4
|
*
|
1013
|
4
|
* If the key is `content`, the value should be a Buffer.
|
1014
|
4
|
* @param {object} [callOptions] Optional parameters. You can override the
|
1015
|
4
|
* default settings for this call, e.g, timeout, retries, paginations,
|
1016
|
4
|
* etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions}
|
1017
|
4
|
* for the details.
|
1018
|
4
|
* @param {function(?Error, ?object)} [callback] The function which will be
|
1019
|
4
|
* called with the result of the API call.
|
1020
|
4
|
*
|
1021
|
4
|
* The second parameter to the callback is an object representing
|
1022
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
1023
|
4
|
* @returns {Promise} The promise which resolves to an array. The first
|
1024
|
4
|
* element of the array is an object representing
|
1025
|
4
|
* [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}.
|
1026
|
4
|
* The promise has a method named "cancel" which cancels the ongoing API
|
1027
|
4
|
* call.
|
1028
|
4
|
*
|
1029
|
4
|
* @example
|
1030
|
4
|
* // Object localization is only available in v1p3beta1.
|
1031
|
4
|
* const vision = require('@google-cloud/vision').v1p3beta1;
|
1032
|
4
|
* const client = new vision.ImageAnnotatorClient();
|
1033
|
4
|
*
|
1034
|
4
|
* const request = {
|
1035
|
4
|
* image: {
|
1036
|
4
|
* source: {imageUri: 'gs://path/to/image.jpg'}
|
1037
|
4
|
* }
|
1038
|
4
|
* };
|
1039
|
4
|
*
|
1040
|
4
|
* client
|
1041
|
4
|
* .objectLocalization(request)
|
1042
|
4
|
* .then(response => {
|
1043
|
4
|
* // doThingsWith(response);
|
1044
|
4
|
* })
|
1045
|
4
|
* .catch(err => {
|
1046
|
4
|
* console.error(err);
|
1047
|
4
|
* });
|
1048
|
4
|
*/
|
1049
|
4
|
if (features!.OBJECT_LOCALIZATION !== undefined) {
|
1050
|
4
|
methods.objectLocalization = promisify(
|
1051
|
4
|
_createSingleFeatureMethod(features!.OBJECT_LOCALIZATION)
|
1052
|
4
|
);
|
1053
|
4
|
}
|
1054
|
4
|
return methods;
|
1055
|
4
|
}
|