0

尝试使用节点通过视觉 api 运行标签检测:

'use strict';
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');

// Creates a client
const client = new ImageAnnotatorClient({
projectId: 'my-project-xxx',
 keyFilename: 'Users/xxx/Downloads/xxx.json',
});

// Performs label detection on the image file
client
 .labelDetection('.//Users/xxx/Downloads/menu.jpg')
 .then(results => {
   const labels = results[0].labelAnnotations;

console.log('Labels:');
labels.forEach(label => console.log(label.description));
})
.catch(err => {
  console.error('ERROR:', err);
 });

不断收到错误:“ImageAnnotatorClient 未定义”有什么原因吗?

4

1 回答 1

2

您可以尝试修改该行:

const client = new ImageAnnotatorClient({

为了:

const client = new vision.ImageAnnotatorClient({

ImageAnnotatorClient 方法是从您作为vision变量导入的 Cloud Vision API 中提取的。

于 2018-01-17T15:15:15.800 回答