Skip to content

Commit

Permalink
vision: support ImageContext in detect requests (#1342)
Browse files Browse the repository at this point in the history
* vision: support ImageContext in detect requests

ImageContext allows the user to provide "hints" about the content of the image to the Vision API. See https://cloud.google.com/vision/reference/rest/v1/images/annotate#ImageContext.

* Added name to authors/contributors

* Removed trailing whitespace

* vision: Alphabetizing imageContext docs and handler locations, simplifying imageContext docs

* vision: Adding test for imageContext

* vision: Fixing doc formatting for imageContext
  • Loading branch information
okofish authored and stephenplusplus committed May 26, 2016
1 parent ec5a8f6 commit 7ff0a5b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
Google Inc.
Anand Suresh
Brett Bergmann
Jesse Friedman
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Brett Bergmann <[email protected]>
Burcu Dogan <[email protected]>
Hector Rovira <[email protected]>
Ido Shamun <[email protected]>
Jesse Friedman <[email protected]>
Johan Euphrosine <[email protected]>
Marco Ziccardi <[email protected]>
Patrick Costello <[email protected]>
Expand Down
7 changes: 7 additions & 0 deletions lib/vision/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ Vision.prototype.annotate = function(requests, callback) {
* image path, a remote image URL, or a gcloud File object.
* @param {string[]|object=} options - An array of types or a configuration
* object.
* @param {object=} options.imageContext - See an
* [`ImageContext`](https://cloud.google.com/vision/reference/rest/v1/images/annotate#ImageContext)
* resource.
* @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
Expand Down Expand Up @@ -312,6 +315,10 @@ Vision.prototype.detect = function(images, options, callback) {
}
};

if (is.object(options.imageContext)) {
cfg.imageContext = options.imageContext;
}

if (is.number(options.maxResults)) {
cfg.features.maxResults = options.maxResults;
}
Expand Down
34 changes: 34 additions & 0 deletions test/vision/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,40 @@ describe('Vision', function() {
async.each(shortNames, checkConfig, done);
});

it('should allow setting imageContext', function(done) {
var imageContext = {
latLongRect: {
minLatLng: {
latitude: 37.420901,
longitude: -122.081293
},
maxLatLng: {
latitude: 37.423228,
longitude: -122.086347
}
}
};

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

done();
};

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

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

Expand Down

0 comments on commit 7ff0a5b

Please sign in to comment.