-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-detection.js
32 lines (26 loc) · 1.01 KB
/
text-detection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// See API documentation at: https://cloud.google.com/vision/docs/detecting-text
require('dotenv-extended').load();
var request = require('request-promise').defaults({ encoding: null });
// Google vision service
const Vision = require('@google-cloud/vision');
const vision = Vision({
projectId: process.env.PROJECT_ID,
keyFilename: process.env.GOOGLE_VISION_KEY_LOCATION
});
let testUri = "http://cdn.newsapi.com.au/image/v1/695cf4545bf9ae93079124397bcf43c3";
function textDetection(imageUrl) {
return new Promise(function (resolve) {
request(imageUrl).then((response) => {
return vision.textDetection({ content: new Buffer(response).toString("base64") });
}).then((results) => {
const detections = results[0].textAnnotations;
console.log('Text: ', detections[0]);
resolve(detections[0].description);
}).catch((error) => {
console.log(error);
});
});
}
var exports = module.exports = {
textDetection: textDetection
}