-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision_try.js
116 lines (97 loc) · 3.44 KB
/
vision_try.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require("dotenv").config({ path: "./.env" });
const vision = require("@google-cloud/vision");
// Create a Vision client
const client = new vision.ImageAnnotatorClient();
// Specify the image path
// const imagePath = "googlelogo.png";
const imagePaths = ["googlelogo.png", "shopping.webp", "bisleri-fake.jpg"];
// // Make a label detection request
// client
// // .labelDetection(imagePath)
// // .logoDetection(imagePath)
// // .then((results) => {
// // const logos = results[0].logoAnnotations;
// // // Check if logos is defined
// // if (logos && logos.length > 0) {
// // console.log("Logos detected:");
// // logos.forEach((logo) => {
// // console.log(logo.description + " (" + logo.score + ")");
// // });
// // } else {
// // console.log("No logos detected.");
// // }
// .labelDetection(imagePath)
// .then((labelResults) => {
// const labels = labelResults[0].labelAnnotations;
// console.log("Labels detected:");
// labels.forEach((label) => {
// console.log(label.description + " (" + label.score + ")");
// });
// // Make a separate logo detection request
// return client.logoDetection(imagePath);
// })
// .then((logoResults) => {
// const logos = logoResults[0].logoAnnotations;
// console.log("Logos detected:");
// logos.forEach((logo) => {
// console.log(logo.description + " (" + logo.score + ")");
// });
// })
// .catch((error) => {
// console.error("Error:", error);
// });
// client
// .labelDetection(imagePath)
// .then((labelResults) => {
// const labels = labelResults[0].labelAnnotations;
// // Check if labels is defined and contains at least one label
// if (labels && labels.length > 0) {
// const topLabel = labels[0];
// console.log("Top label detected:");
// console.log(topLabel.description + " (" + topLabel.score + ")");
// } else {
// console.log("No labels detected.");
// }
// // Make a separate logo detection request
// return client.logoDetection(imagePath);
// })
// .then((logoResults) => {
// const logos = logoResults[0].logoAnnotations;
// // Check if logos is defined and contains at least one logo
// if (logos && logos.length > 0) {
// const topLogo = logos[0];
// console.log("Top logo detected:");
// console.log(topLogo.description + " (" + topLogo.score + ")");
// } else {
// console.log("No logos detected.");
// }
// })
// .catch((error) => {
// console.error("Error:", error);
// });
imagePaths.forEach((imagePath) => {
client
.labelDetection(imagePath)
.then((labelResults) => {
const labels = labelResults[0].labelAnnotations;
if (labels && labels.length > 0) {
const topLabel = labels[0];
console.log(`Top label for ${imagePath}: ${topLabel.description} (${topLabel.score})`);
} else {
console.log(`No labels detected for ${imagePath}.`);
}
return client.logoDetection(imagePath);
})
.then((logoResults) => {
const logos = logoResults[0].logoAnnotations;
if (logos && logos.length > 0) {
const topLogo = logos[0];
console.log(`Top logo for ${imagePath}: ${topLogo.description} (${topLogo.score})`);
} else {
console.log(`No logos detected for ${imagePath}.`);
}
})
.catch((error) => {
console.error(`Error processing ${imagePath}:`, error);
});
});