-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgcv.js
43 lines (40 loc) · 1.05 KB
/
gcv.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
33
34
35
36
37
38
39
40
41
42
43
// Functions related to working with Google Cloud Vision
const vision = require('@google-cloud/vision');
const fs = require('fs');
// Hit GCV with an image to OCR and return the results
function performGCV(requests) {
// GCV Client
const client = new vision.ImageAnnotatorClient({
keyFilename: './credentials.json'
});
// Performs label detection on the image file
return client
.batchAnnotateImages({requests: requests})
.then(results => {
return results
})
}
// Take an image path and output the data in a GCV compatible stream
function prepareGCV(images) {
return images.map(image => {
return {
fileName: image,
image: {
content: fs.readFileSync(image)
}
}
})
.map(d => {
return {
image: d.image,
features: [{
type: "DOCUMENT_TEXT_DETECTION",
model: 'builtin/latest'
}]
}
})
}
module.exports = {
performGCV: performGCV,
prepareGCV: prepareGCV
}