【问题标题】:ImageAnnotatorClient google vision APIImageAnnotatorClient 谷歌视觉 API
【发布时间】:2018-01-17 23:15:15
【问题描述】:

尝试使用节点通过视觉 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 未定义” 这有什么原因吗?

【问题讨论】:

    标签: google-cloud-platform vision-api


    【解决方案1】:

    你可以尝试修改行吗:

    const client = new ImageAnnotatorClient({
    

    为:

    const client = new vision.ImageAnnotatorClient({
    

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

    【讨论】:

    • 我试过这个,但是返回这个错误:“TypeError: vision.ImageAnnotatorClient is not a constructor”
    • 您运行的是哪个版本的库? (npm ls @google-cloud/vision)
    • 升级包到最新版本(0.14.0):npm install --save @google-cloud/vision
    猜你喜欢
    • 2019-10-13
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多