Skip to content

Commit 3b7e155

Browse files
authored
Initial commit
1 parent 1a2af4e commit 3b7e155

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//Copyright (c) Microsoft Corporation. All rights reserved.
2+
//Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
let https = require('https');
7+
8+
/* Add a valid Azure Computer Vision endpoint to your environment variables.
9+
Example https://northeurope.api.cognitive.microsoft.com/
10+
*/
11+
let endpoint = process.env['COMPUTER_VISION_ENDPOINT']
12+
13+
/* Add a valid Azure Computer Vision subscription key to your environment variables.
14+
Also note v5 and v7 require separate subscription keys.
15+
*/
16+
let key = process.env['COMPUTER_VISION_SUBSCRIPTION_KEY'];
17+
18+
/* Use this url image with text, or replace with your own
19+
*/
20+
let url = 'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/printed_text.jpg';
21+
let detectOrientation = false;
22+
23+
const ComputerVisionClient = require('azure-cognitiveservices-computervision');
24+
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
25+
26+
let credentials = new CognitiveServicesCredentials(key);
27+
let client = new ComputerVisionClient(credentials, endpoint);
28+
29+
client.recognizePrintedText(detectOrientation, url)
30+
.then(ocrResult => {
31+
printOcrResult(ocrResult);
32+
});
33+
34+
function printOcrResult(ocrResult) {
35+
console.log('OcrResult')
36+
console.log(`language: ${ocrResult.language}`)
37+
console.log(`textAngle: ${ocrResult.textAngle}`)
38+
console.log(`orientation: ${ocrResult.orientation}`)
39+
40+
ocrResult.regions.forEach((r, ri) => {
41+
console.log(`\tRegion ${ri} - boundingBox: ${r.boundingBox}`)
42+
43+
r.lines.forEach((l, li) => {
44+
console.log(`\t\tLine ${li} - boundingBox: ${l.boundingBox}`)
45+
46+
l.words.forEach((w, wi) => {
47+
console.log(`\t\t\tWord ${wi} - boundingBox: ${w.boundingBox}`)
48+
console.log(`\t\t\ttext: ${w.text}`)
49+
})
50+
51+
});
52+
53+
});
54+
}

0 commit comments

Comments
 (0)