Skip to content

Commit

Permalink
Vision snippets. (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored Jan 10, 2017
1 parent ef7d36f commit 4e070aa
Show file tree
Hide file tree
Showing 13 changed files with 878 additions and 19 deletions.
436 changes: 436 additions & 0 deletions vision/samples/detect.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions vision/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"license": "Apache Version 2.0",
"author": "Google Inc.",
"scripts": {
"test": "cd ..; npm run st -- --verbose vision/system-test/*.test.js"
"test": "cd ..; npm run st -- --verbose vision/system-test/detect.test.js"
},
"dependencies": {
"@google-cloud/storage": "0.6.0",
"@google-cloud/vision": "0.7.0",
"async": "2.1.4",
"natural": "0.4.0",
"redis": "2.6.3"
"redis": "2.6.3",
"yargs": "6.6.0"
},
"optionalDependencies": {
"canvas": "1.6.2"
Expand Down
Binary file added vision/samples/resources/face_no_surprise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/samples/resources/landmark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/samples/resources/logos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/samples/resources/text.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vision/samples/resources/water.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 132 additions & 0 deletions vision/samples/system-test/detect.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

require(`../../system-test/_setup`);

const path = require(`path`);
const storage = require(`@google-cloud/storage`)();
const uuid = require(`uuid`);

const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
const cmd = `node detect.js`;
const cwd = path.join(__dirname, `..`);
const files = [
`face_no_surprise.jpg`,
`landmark.jpg`,
`logos.png`,
`text.jpg`,
`wakeupcat.jpg`
].map((name) => {
return {
name,
localPath: path.resolve(path.join(__dirname, `../resources/${name}`))
};
});

test.before(async () => {
const [bucket] = await storage.createBucket(bucketName);
await Promise.all(files.map((file) => bucket.upload(file.localPath)));
});

test.after.always(async () => {
const bucket = storage.bucket(bucketName);
await bucket.deleteFiles({ force: true });
await bucket.deleteFiles({ force: true }); // Try a second time...
await bucket.delete();
});

test(`should detect faces in a local file`, async (t) => {
const output = await runAsync(`${cmd} faces ${files[0].localPath}`, cwd);
t.true(output.includes(`Faces:`));
t.true(output.includes(`Face #1:`));
});

test(`should detect faces in a remote file`, async (t) => {
const output = await runAsync(`${cmd} faces-gcs ${bucketName} ${files[0].name}`, cwd);
t.true(output.includes(`Faces:`));
t.true(output.includes(`Face #1:`));
});

test(`should detect labels in a local file`, async (t) => {
const output = await runAsync(`${cmd} labels ${files[4].localPath}`, cwd);
t.true(output.includes(`Labels:`));
t.true(output.includes(`cat`));
});

test(`should detect labels in a remote file`, async (t) => {
const output = await runAsync(`${cmd} labels-gcs ${bucketName} ${files[4].name}`, cwd);
t.true(output.includes(`Labels:`));
t.true(output.includes(`cat`));
});

test(`should detect landmarks in a local file`, async (t) => {
const output = await runAsync(`${cmd} landmarks ${files[1].localPath}`, cwd);
t.true(output.includes(`Landmarks:`));
t.true(output.includes(`Palace of Fine Arts`));
});

test(`should detect landmarks in a remote file`, async (t) => {
const output = await runAsync(`${cmd} landmarks-gcs ${bucketName} ${files[1].name}`, cwd);
t.true(output.includes(`Landmarks:`));
t.true(output.includes(`Palace of Fine Arts`));
});

test(`should detect text in a local file`, async (t) => {
const output = await runAsync(`${cmd} text ${files[3].localPath}`, cwd);
t.true(output.includes(`Text:`));
t.true(output.includes(`System Software Update`));
});

test(`should detect text in a remote file`, async (t) => {
const output = await runAsync(`${cmd} text-gcs ${bucketName} ${files[3].name}`, cwd);
t.true(output.includes(`Text:`));
t.true(output.includes(`System Software Update`));
});

test(`should detect logos in a local file`, async (t) => {
const output = await runAsync(`${cmd} logos ${files[2].localPath}`, cwd);
t.true(output.includes(`Logos:`));
t.true(output.includes(`Google`));
});

test(`should detect logos in a remote file`, async (t) => {
const output = await runAsync(`${cmd} logos-gcs ${bucketName} ${files[2].name}`, cwd);
t.true(output.includes(`Logos:`));
t.true(output.includes(`Google`));
});

test(`should detect properties in a local file`, async (t) => {
const output = await runAsync(`${cmd} properties ${files[1].localPath}`, cwd);
t.true(output.includes(`Colors:`));
t.true(output.split(`\n`).length > 4, `Multiple colors were detected.`);
});

test(`should detect properties in a remote file`, async (t) => {
const output = await runAsync(`${cmd} properties-gcs ${bucketName} ${files[1].name}`, cwd);
t.true(output.includes(`Colors:`));
t.true(output.split(`\n`).length > 4, `Multiple colors were detected.`);
});

test(`should detect safe-search in a local file`, async (t) => {
const output = await runAsync(`${cmd} safe-search ${files[4].localPath}`, cwd);
t.true(output.includes(`Medical:`));
});

test(`should detect safe-search in a remote file`, async (t) => {
const output = await runAsync(`${cmd} safe-search-gcs ${bucketName} ${files[4].name}`, cwd);
t.true(output.includes(`Medical:`));
});
2 changes: 1 addition & 1 deletion vision/samples/system-test/faceDetection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const inputFile = path.join(__dirname, `../resources`, `face.png`);
const outputFile = path.join(__dirname, `../../vision`, `out.png`);

test.before(stubConsole);
test.after(restoreConsole);
test.after.always(restoreConsole);

test.cb(`should detect faces`, (t) => {
faceDetectionExample.main(inputFile, outputFile, MockCanvas, (err, faces) => {
Expand Down
2 changes: 1 addition & 1 deletion vision/samples/system-test/labelDetection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const labelDetectionSample = require(`../labelDetection`);
const inputFile = path.join(__dirname, `../resources`, `cat.jpg`);

test.before(stubConsole);
test.after(restoreConsole);
test.after.always(restoreConsole);

test.cb(`should detect labels`, (t) => {
labelDetectionSample.main(inputFile, (err, labels) => {
Expand Down
2 changes: 1 addition & 1 deletion vision/samples/system-test/landmarkDetection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const landmarkDetectionSample = require(`../landmarkDetection`);
const inputFile = `https://cloud-samples-tests.storage.googleapis.com/vision/water.jpg`;

test.before(stubConsole);
test.after(restoreConsole);
test.after.always(restoreConsole);

test.cb(`should detect landmarks`, (t) => {
landmarkDetectionSample.main(inputFile, (err, landmarks) => {
Expand Down
2 changes: 1 addition & 1 deletion vision/samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const vision = proxyquire(`@google-cloud/vision`, {})();
const path = require(`path`);

test.before(stubConsole);
test.after(restoreConsole);
test.after.always(restoreConsole);

test.cb(`should detect labels`, (t) => {
const filePath = path.join(__dirname, `../resources/wakeupcat.jpg`);
Expand Down
Loading

0 comments on commit 4e070aa

Please sign in to comment.