Showing
1 changed file
with
38 additions
and
0 deletions
get-printed-text.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const request = require('request'); | ||
4 | + | ||
5 | +let subscriptionKey = process.env['COMPUTER_VISION_SUBSCRIPTION_KEY']; | ||
6 | +let endpoint = process.env['COMPUTER_VISION_ENDPOINT'] | ||
7 | +if (!subscriptionKey) { throw new Error('Set your environment variables for your subscription key and endpoint.'); } | ||
8 | + | ||
9 | +var uriBase = endpoint + 'vision/v2.1/ocr'; | ||
10 | + | ||
11 | +const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/' + | ||
12 | + 'Atomist_quote_from_Democritus.png/338px-Atomist_quote_from_Democritus.png'; | ||
13 | + | ||
14 | +// Request parameters. | ||
15 | +const params = { | ||
16 | + 'language': 'unk', | ||
17 | + 'detectOrientation': 'true', | ||
18 | +}; | ||
19 | + | ||
20 | +const options = { | ||
21 | + uri: uriBase, | ||
22 | + qs: params, | ||
23 | + body: '{"url": ' + '"' + imageUrl + '"}', | ||
24 | + headers: { | ||
25 | + 'Content-Type': 'application/json', | ||
26 | + 'Ocp-Apim-Subscription-Key' : subscriptionKey | ||
27 | + } | ||
28 | +}; | ||
29 | + | ||
30 | +request.post(options, (error, response, body) => { | ||
31 | + if (error) { | ||
32 | + console.log('Error: ', error); | ||
33 | + return; | ||
34 | + } | ||
35 | + let jsonResponse = JSON.stringify(JSON.parse(body), null, ' '); | ||
36 | + console.log('JSON Response\n'); | ||
37 | + console.log(jsonResponse); | ||
38 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment