Skip to content

Commit 7ff0a5b

Browse files
okofishstephenplusplus
authored andcommitted
vision: support ImageContext in detect requests (#1342)
* 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
1 parent ec5a8f6 commit 7ff0a5b

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
Google Inc.
1010
Anand Suresh
1111
Brett Bergmann
12+
Jesse Friedman

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Brett Bergmann <[email protected]>
1717
Burcu Dogan <[email protected]>
1818
Hector Rovira <[email protected]>
1919
Ido Shamun <[email protected]>
20+
Jesse Friedman <[email protected]>
2021
Johan Euphrosine <[email protected]>
2122
Marco Ziccardi <[email protected]>
2223
Patrick Costello <[email protected]>

lib/vision/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ Vision.prototype.annotate = function(requests, callback) {
187187
* image path, a remote image URL, or a gcloud File object.
188188
* @param {string[]|object=} options - An array of types or a configuration
189189
* object.
190+
* @param {object=} options.imageContext - See an
191+
* [`ImageContext`](https://cloud.google.com/vision/reference/rest/v1/images/annotate#ImageContext)
192+
* resource.
190193
* @param {number} options.maxResults - The maximum number of results, per type,
191194
* to return in the response.
192195
* @param {string[]} options.types - An array of feature types to detect from
@@ -312,6 +315,10 @@ Vision.prototype.detect = function(images, options, callback) {
312315
}
313316
};
314317

318+
if (is.object(options.imageContext)) {
319+
cfg.imageContext = options.imageContext;
320+
}
321+
315322
if (is.number(options.maxResults)) {
316323
cfg.features.maxResults = options.maxResults;
317324
}

test/vision/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,40 @@ describe('Vision', function() {
311311
async.each(shortNames, checkConfig, done);
312312
});
313313

314+
it('should allow setting imageContext', function(done) {
315+
var imageContext = {
316+
latLongRect: {
317+
minLatLng: {
318+
latitude: 37.420901,
319+
longitude: -122.081293
320+
},
321+
maxLatLng: {
322+
latitude: 37.423228,
323+
longitude: -122.086347
324+
}
325+
}
326+
};
327+
328+
vision.annotate = function(config) {
329+
assert.deepEqual(config, [
330+
{
331+
image: IMAGES[0],
332+
features: {
333+
type: 'LABEL_DETECTION'
334+
},
335+
imageContext: imageContext
336+
}
337+
]);
338+
339+
done();
340+
};
341+
342+
vision.detect(IMAGE, {
343+
types: ['label'],
344+
imageContext: imageContext
345+
}, assert.ifError);
346+
});
347+
314348
it('should allow setting maxResults', function(done) {
315349
var maxResults = 10;
316350

0 commit comments

Comments
 (0)