|
1 | | -# @google-cloud/vision ([Beta][versioning]) |
2 | | -> Cloud Vision Client Library for Node.js |
| 1 | +# Node.js Client for Google Cloud Vision API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-node#versioning)) |
3 | 2 |
|
4 | | -*Looking for more Google APIs than just Vision? You might want to check out [`google-cloud`][google-cloud].* |
| 3 | +[Google Cloud Vision API][Product Documentation]: Integrates Google Vision features, including image labeling, face, logo, and landmark detection, optical character recognition (OCR), and detection of explicit content, into applications. |
| 4 | +- [Client Library Documentation][] |
| 5 | +- [Product Documentation][] |
5 | 6 |
|
6 | | -- [API Documentation][gcloud-vision-docs] |
7 | | -- [Official Documentation][cloud-vision-docs] |
| 7 | +## Quick Start |
| 8 | +In order to use this library, you first need to go through the following steps: |
8 | 9 |
|
| 10 | +1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) |
| 11 | +2. [Enable the Google Cloud Vision API.](https://console.cloud.google.com/apis/api/vision) |
| 12 | +3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/master/guides/authentication) |
9 | 13 |
|
10 | | -```sh |
11 | | -$ npm install --save @google-cloud/vision |
| 14 | +### Installation |
12 | 15 | ``` |
13 | | -```js |
14 | | -var vision = require('@google-cloud/vision')({ |
15 | | - projectId: 'grape-spaceship-123', |
16 | | - keyFilename: '/path/to/keyfile.json' |
17 | | -}); |
18 | | - |
19 | | -// Read the text from an image. |
20 | | -vision.detectText('./image.jpg', function(err, text) { |
21 | | - // text = [ |
22 | | - // 'This was text found in the image', |
23 | | - // 'This was more text found in the image' |
24 | | - // ] |
25 | | -}); |
26 | | - |
27 | | -// Detect faces and the locations of their features in an image. |
28 | | -vision.detectFaces('./image.jpg', function(err, faces) { |
29 | | - // faces = [ |
30 | | - // { |
31 | | - // angles: {pan,tilt,roll}, |
32 | | - // bounds: { |
33 | | - // head: [{x,y},{x,y},{x,y},{x,y}], |
34 | | - // face: [{x,y},{x,y},{x,y},{x,y}] |
35 | | - // }, |
36 | | - // features: { |
37 | | - // confidence: 34.489909, |
38 | | - // chin: { |
39 | | - // center: {x,y,z}, |
40 | | - // left: {x,y,z}, |
41 | | - // right: {x,y,z} |
42 | | - // }, |
43 | | - // ears: { |
44 | | - // left: {x,y,z}, |
45 | | - // right: {x,y,z} |
46 | | - // }, |
47 | | - // eyebrows: { |
48 | | - // left: { |
49 | | - // left: {x,y,z}, |
50 | | - // right: {x,y,z}, |
51 | | - // top: {x,y,z} |
52 | | - // }, |
53 | | - // right: { |
54 | | - // left: {x,y,z}, |
55 | | - // right: {x,y,z}, |
56 | | - // top: {x,y,z} |
57 | | - // } |
58 | | - // }, |
59 | | - // eyes: { |
60 | | - // left: { |
61 | | - // bottom: {x,y,z}, |
62 | | - // center: {x,y,z}, |
63 | | - // left: {x,y,z}, |
64 | | - // pupil: {x,y,z}, |
65 | | - // right: {x,y,z}, |
66 | | - // top: {x,y,z} |
67 | | - // }, |
68 | | - // right: { |
69 | | - // bottom: {x,y,z}, |
70 | | - // center: {x,y,z}, |
71 | | - // left: {x,y,z}, |
72 | | - // pupil: {x,y,z}, |
73 | | - // right: {x,y,z}, |
74 | | - // top: {x,y,z} |
75 | | - // } |
76 | | - // }, |
77 | | - // forehead: {x,y,z}, |
78 | | - // lips: { |
79 | | - // bottom: {x,y,z}, |
80 | | - // top: {x,y,z} |
81 | | - // }, |
82 | | - // mouth: { |
83 | | - // center: {x,y,z}, |
84 | | - // left: {x,y,z}, |
85 | | - // right: {x,y,z} |
86 | | - // }, |
87 | | - // nose: { |
88 | | - // bottom: { |
89 | | - // center: {x,y,z}, |
90 | | - // left: {x,y,z}, |
91 | | - // right: {x,y,z} |
92 | | - // }, |
93 | | - // tip: {x,y,z}, |
94 | | - // top: {x,y,z} |
95 | | - // } |
96 | | - // }, |
97 | | - // confidence: 56.748849, |
98 | | - // blurry: false, |
99 | | - // dark: false, |
100 | | - // happy: false, |
101 | | - // hat: false, |
102 | | - // mad: false, |
103 | | - // sad: false, |
104 | | - // surprised: false |
105 | | - // } |
106 | | - // ] |
107 | | -}); |
108 | | - |
109 | | -// Promises are also supported by omitting callbacks. |
110 | | -vision.detectFaces('./image.jpg').then(function(data) { |
111 | | - var faces = data[0]; |
112 | | -}); |
113 | | - |
114 | | -// It's also possible to integrate with third-party Promise libraries. |
115 | | -var vision = require('@google-cloud/vision')({ |
116 | | - promise: require('bluebird') |
117 | | -}); |
118 | | -``` |
119 | | - |
120 | | - |
121 | | -## Authentication |
122 | | - |
123 | | -It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Cloud services. |
124 | | - |
125 | | -### On Google Cloud Platform |
126 | | - |
127 | | -If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access. |
128 | | - |
129 | | -``` js |
130 | | -var vision = require('@google-cloud/vision')(); |
131 | | -// ...you're good to go! |
| 16 | +$ npm install --save @google-cloud/vision |
132 | 17 | ``` |
133 | 18 |
|
134 | | -### Elsewhere |
135 | | - |
136 | | -If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account: |
137 | | - |
138 | | -1. Visit the [Google Developers Console][dev-console]. |
139 | | -2. Create a new project or click on an existing project. |
140 | | -3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services): |
141 | | - * Google Cloud Vision API |
142 | | -4. Navigate to **APIs & auth** > **Credentials** and then: |
143 | | - * If you want to use a new service account, click on **Create new Client ID** and select **Service account**. After the account is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests. |
144 | | - * If you want to generate a new key for an existing service account, click on **Generate new JSON key** and download the JSON key file. |
145 | | - |
146 | | -``` js |
147 | | -var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123' |
148 | | - |
149 | | -var vision = require('@google-cloud/vision')({ |
150 | | - projectId: projectId, |
151 | | - |
152 | | - // The path to your key file: |
153 | | - keyFilename: '/path/to/keyfile.json' |
154 | | - |
155 | | - // Or the contents of the key file: |
156 | | - credentials: require('./path/to/keyfile.json') |
157 | | -}); |
158 | | - |
159 | | -// ...you're good to go! |
| 19 | +### Preview |
| 20 | +#### ImageAnnotatorClient |
| 21 | +```js |
| 22 | + var vision = require('@google-cloud/vision'); |
| 23 | + |
| 24 | + var client = vision({ |
| 25 | + // optional auth parameters. |
| 26 | + }); |
| 27 | + |
| 28 | + var gcsImageUri = 'gs://gapic-toolkit/President_Barack_Obama.jpg'; |
| 29 | + var source = { |
| 30 | + gcsImageUri : gcsImageUri |
| 31 | + }; |
| 32 | + var image = { |
| 33 | + source : source |
| 34 | + }; |
| 35 | + var type = vision.v1.types.Feature.Type.FACE_DETECTION; |
| 36 | + var featuresElement = { |
| 37 | + type : type |
| 38 | + }; |
| 39 | + var features = [featuresElement]; |
| 40 | + var requestsElement = { |
| 41 | + image : image, |
| 42 | + features : features |
| 43 | + }; |
| 44 | + var requests = [requestsElement]; |
| 45 | + client.batchAnnotateImages({requests: requests}).then(function(responses) { |
| 46 | + var response = responses[0]; |
| 47 | + // doThingsWith(response) |
| 48 | + }) |
| 49 | + .catch(function(err) { |
| 50 | + console.error(err); |
| 51 | + }); |
160 | 52 | ``` |
161 | 53 |
|
| 54 | +### Next Steps |
| 55 | +- Read the [Client Library Documentation][] for Google Cloud Vision API to see other available methods on the client. |
| 56 | +- Read the [Google Cloud Vision API Product documentation][Product Documentation] to learn more about the product and see How-to Guides. |
| 57 | +- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/README.md) to see the full list of Cloud APIs that we cover. |
162 | 58 |
|
163 | | -[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning |
164 | | -[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/ |
165 | | -[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using |
166 | | -[dev-console]: https://console.developers.google.com/project |
167 | | -[gcloud-vision-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/vision |
168 | | -[cloud-vision-docs]: https://cloud.google.com/vision/docs |
| 59 | +[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/vision |
| 60 | +[Product Documentation]: https://cloud.google.com/vision |
0 commit comments