-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-vision.js
39 lines (32 loc) · 1023 Bytes
/
google-vision.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
require("dotenv").config();
const vision = require("@google-cloud/vision");
const credential = JSON.parse(
Buffer.from(process.env.GOOGLE_SERVICE_KEY, "base64").toString()
);
// Create a client
// const client = new vision.ImageAnnotatorClient({
// keyFilename: "../KeepSafe/boardsong-143-79ceb15a2ef7.json",
// });
const client = new vision.ImageAnnotatorClient({
credentials: {
client_email: credential.client_email,
private_key: credential.private_key,
},
});
all_labels = [];
const getLabels = async (imageList) => {
const all_labels = [];
for (const imageUrl of imageList) {
try {
const [result] = await client.labelDetection(imageUrl);
const labels = result.labelAnnotations;
const image_label = labels.map((label) => label.description);
all_labels.push(image_label);
// console.log(image_label);
} catch (error) {
console.error(`Error processing image ${imageUrl}:`, error.message);
}
}
return all_labels;
};
module.exports = getLabels;