| 200 | } |
| 201 | |
| 202 | async function detectLogos(fileName) { |
| 203 | // [START vision_logo_detection] |
| 204 | const vision = require('@google-cloud/vision'); |
| 205 | const fs = require('fs'); |
| 206 | |
| 207 | // Creates a client |
| 208 | const client = new vision.ImageAnnotatorClient(); |
| 209 | |
| 210 | /** |
| 211 | * TODO(developer): Uncomment the following line before running the sample. |
| 212 | */ |
| 213 | // const fileName = 'Local image file, e.g. /path/to/image.png'; |
| 214 | |
| 215 | const imageBuffer = fs.readFileSync(fileName); |
| 216 | const base64Image = imageBuffer.toString('base64'); |
| 217 | |
| 218 | const request = { |
| 219 | requests: [ |
| 220 | { |
| 221 | image: { |
| 222 | content: base64Image, |
| 223 | }, |
| 224 | features: [ |
| 225 | { |
| 226 | type: 'LOGO_DETECTION', |
| 227 | }, |
| 228 | ], |
| 229 | }, |
| 230 | ], |
| 231 | }; |
| 232 | |
| 233 | // Performs logo detection on the local file |
| 234 | const [response] = await client.batchAnnotateImages(request); |
| 235 | |
| 236 | response.responses.forEach(res => { |
| 237 | if (res.logoAnnotations) { |
| 238 | console.log('Logos:'); |
| 239 | res.logoAnnotations.forEach(logo => console.log(logo)); |
| 240 | } |
| 241 | |
| 242 | if (res.error) { |
| 243 | console.error(` - Error: ${res.error.message}`); |
| 244 | } |
| 245 | }); |
| 246 | // [END vision_logo_detection] |
| 247 | } |
| 248 | |
| 249 | async function detectLogosGCS(bucketName, fileName) { |
| 250 | // [START vision_logo_detection_gcs] |