Skip to content

Commit f30b074

Browse files
committed
Add Cloud Vision text detection sample.
1 parent 18d8e96 commit f30b074

File tree

13 files changed

+329
-6
lines changed

13 files changed

+329
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ __Other Examples__
117117
- Face detection - [Source code][vision_1] | [Documentation][vision_2]
118118
- Label detection - [Source code][vision_3] | [Documentation][vision_4]
119119
- Landmark detection - [Source code][vision_5] | [Documentation][vision_6]
120+
- Text detection - [Source code][vision_7] | [Documentation][vision_8]
120121

121122
## Google Prediction API
122123

@@ -328,6 +329,8 @@ See [LICENSE](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/ma
328329
[vision_4]: https://cloud.google.com/vision/docs/label-tutorial
329330
[vision_5]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/vision/landmarkDetection.js
330331
[vision_6]: https://cloud.google.com/vision/docs/landmark-tutorial
332+
[vision_7]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/vision/textDetection.js
333+
[vision_8]: https://cloud.google.com/vision/docs/text-tutorial
331334

332335
[predictionapi_1]: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/prediction/hostedmodels.js
333336
[predictionapi_2]: https://cloud.google.com/prediction/docs/developer-guide#predictionfromappengine

test/vision/textDetection.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2016, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
var test = require('ava');
17+
var path = require('path');
18+
var inputDir = path.resolve('../../vision/resources');
19+
var textDetectionSample = require('../../vision/textDetection');
20+
21+
test.cb('should detect texts', function (t) {
22+
textDetectionSample.main(
23+
inputDir,
24+
function (err, textResponse) {
25+
t.ifError(err);
26+
t.ok(Object.keys(textResponse).length > 0);
27+
t.end();
28+
}
29+
);
30+
});
31+
32+
test.cb('should lookup words', function (t) {
33+
textDetectionSample.lookup(
34+
['the', 'sunbeams', 'in'],
35+
function (err, hits) {
36+
t.ifError(err);
37+
t.ok(hits.length > 0);
38+
t.ok(hits[0].length > 0);
39+
t.end();
40+
}
41+
);
42+
});

vision/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ Execute the sample:
4040
Execute the sample:
4141

4242
node landmarkDetection "https://cloud-samples-tests.storage.googleapis.com/vision/water.jpg"
43+
44+
### Text detection sample
45+
46+
Execute the sample:
47+
48+
node textDetection analyze resources
49+
node textDetection lookup the sunbeams in

vision/not-a-meme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
I am not a meme. Don't fail if you accidently include me in your Vision API
2+
request, please.

vision/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
"engines": {
88
"node": ">=0.10.x"
99
},
10-
"scripts": {
11-
"faceDetection": "node faceDetection.js",
12-
"labelDetection": "node labelDetection.js",
13-
"landmarkDetection": "node landmarkDetection.js"
14-
},
1510
"dependencies": {
11+
"async": "^1.5.0",
12+
"canvas": "^1.3.15",
1613
"gcloud": "^0.32.0",
17-
"canvas": "^1.3.15"
14+
"natural": "^0.4.0",
15+
"redis": "^2.6.0-2"
1816
}
1917
}

vision/resources/bonito.gif

531 KB
Loading

vision/resources/mountain.jpg

40.9 KB
Loading

vision/resources/no-text.jpg

12.1 KB
Loading

vision/resources/sabertooth.gif

633 KB
Loading

vision/resources/succulents.jpg

79.6 KB
Loading

0 commit comments

Comments
 (0)