-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (46 loc) · 1.25 KB
/
index.js
File metadata and controls
63 lines (46 loc) · 1.25 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { text } = require('express');
const express = require('express');
const app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
async function detectText(fileName) {
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// Performs text detection on the local file
try {
const [result] = await client.textDetection(fileName);
const detections = result.textAnnotations;
var page = [];
detections.forEach(text => page.push(text.description));
var pageSpace = page[0];
return pageSpace;
}
catch (e) {
console.log(e);
throw e;
}
}
app.listen(8080, () => {
console.log('listening on port 8080');
})
app.get("/", async (req, res) => {
console.log(req.body.image);
const data = {
image: {
content: Buffer.from(req.body.image, 'base64')
}
}
detectText(data).then(result => {
res.send(result);
})
.catch((err) => {
res.send(err);
})
})