Skip to content

Commit 4d29ab0

Browse files
vision: support maxResults
1 parent 3a4e008 commit 4d29ab0

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

lib/vision/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,14 @@ Vision.prototype.annotate = function(requests, callback) {
184184
* @param {string|string[]|module:storage/file|module:storage/file[]} images -
185185
* The source image(s) to run the detection on. It can be either a local
186186
* image path or a gcloud File object.
187-
* @param {string[]|object} config - An array of types or a configuration
187+
* @param {string[]|object=} options - An array of types or a configuration
188188
* object.
189-
* @param {string[]} config.types - An array of feature types to detect from the
190-
* provided images. Acceptable values: `faces`, `landmarks`, `labels`,
189+
* @param {number} options.maxResults - The maximum number of results, per type,
190+
* to return in the response.
191+
* @param {string[]} options.types - An array of feature types to detect from
192+
* the provided images. Acceptable values: `faces`, `landmarks`, `labels`,
191193
* `logos`, `properties`, `safeSearch`, `text`.
192-
* @param {boolean=} config.verbose - Use verbose mode, which returns a less-
194+
* @param {boolean=} options.verbose - Use verbose mode, which returns a less-
193195
* simplistic representation of the annotation (default: `false`).
194196
* @param {function} callback - The callback function.
195197
* @param {?error} callback.err - An error returned while making this request.
@@ -292,12 +294,18 @@ Vision.prototype.detect = function(images, options, callback) {
292294
throw new Error('Requested detection feature not found: ' + type);
293295
}
294296

295-
config.push({
297+
var cfg = {
296298
image: image,
297299
features: {
298300
type: typeName
299301
}
300-
});
302+
};
303+
304+
if (is.number(options.maxResults)) {
305+
cfg.features.maxResults = options.maxResults;
306+
}
307+
308+
config.push(cfg);
301309
});
302310
});
303311

test/vision/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,29 @@ describe('Vision', function() {
303303
async.each(shortNames, checkConfig, done);
304304
});
305305

306+
it('should allow setting maxResults', function(done) {
307+
var maxResults = 10;
308+
309+
vision.annotate = function(config) {
310+
assert.deepEqual(config, [
311+
{
312+
image: IMAGES[0],
313+
features: {
314+
type: 'FACE_DETECTION',
315+
maxResults: 10
316+
}
317+
}
318+
]);
319+
320+
done();
321+
};
322+
323+
vision.detect(IMAGE, {
324+
types: ['face'],
325+
maxResults: maxResults
326+
}, assert.ifError);
327+
});
328+
306329
it('should not return detections when none were found', function(done) {
307330
vision.annotate = function(config, callback) {
308331
callback(null, []);

0 commit comments

Comments
 (0)