Skip to content

Commit

Permalink
vision: support maxResults
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Apr 13, 2016
1 parent 3a4e008 commit 4d29ab0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/vision/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ Vision.prototype.annotate = function(requests, callback) {
* @param {string|string[]|module:storage/file|module:storage/file[]} images -
* The source image(s) to run the detection on. It can be either a local
* image path or a gcloud File object.
* @param {string[]|object} config - An array of types or a configuration
* @param {string[]|object=} options - An array of types or a configuration
* object.
* @param {string[]} config.types - An array of feature types to detect from the
* provided images. Acceptable values: `faces`, `landmarks`, `labels`,
* @param {number} options.maxResults - The maximum number of results, per type,
* to return in the response.
* @param {string[]} options.types - An array of feature types to detect from
* the provided images. Acceptable values: `faces`, `landmarks`, `labels`,
* `logos`, `properties`, `safeSearch`, `text`.
* @param {boolean=} config.verbose - Use verbose mode, which returns a less-
* @param {boolean=} options.verbose - Use verbose mode, which returns a less-
* simplistic representation of the annotation (default: `false`).
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
Expand Down Expand Up @@ -292,12 +294,18 @@ Vision.prototype.detect = function(images, options, callback) {
throw new Error('Requested detection feature not found: ' + type);
}

config.push({
var cfg = {
image: image,
features: {
type: typeName
}
});
};

if (is.number(options.maxResults)) {
cfg.features.maxResults = options.maxResults;
}

config.push(cfg);
});
});

Expand Down
23 changes: 23 additions & 0 deletions test/vision/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,29 @@ describe('Vision', function() {
async.each(shortNames, checkConfig, done);
});

it('should allow setting maxResults', function(done) {
var maxResults = 10;

vision.annotate = function(config) {
assert.deepEqual(config, [
{
image: IMAGES[0],
features: {
type: 'FACE_DETECTION',
maxResults: 10
}
}
]);

done();
};

vision.detect(IMAGE, {
types: ['face'],
maxResults: maxResults
}, assert.ifError);
});

it('should not return detections when none were found', function(done) {
vision.annotate = function(config, callback) {
callback(null, []);
Expand Down

0 comments on commit 4d29ab0

Please sign in to comment.