首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase云函数& Cloud Vision接口: TypeError: vision.detectText不是函数

Firebase云函数& Cloud Vision接口: TypeError: vision.detectText不是函数
EN

Stack Overflow用户
提问于 2017-12-23 04:00:09
回答 1查看 1.3K关注 0票数 2

我尝试在Firebase Cloud function中使用Cloud Vision API来OCR存储在Firebase Storage中的图像。

我导入Google Cloud vision客户端库,如下所示

代码语言:javascript
复制
const vision = require('@google-cloud/vision');

然后我会打电话给

代码语言:javascript
复制
vision.detectText({ source: { imageUri: 'gs://xxxx.appspot.com/yyyy.JPG' } }) 

但是,我得到了一个错误

TypeError: vision.detectText不是函数

最初我用的是

代码语言:javascript
复制
vision.textDetection({ source: { imageUri: ... } })

从这个例子中,https://cloud.google.com/vision/docs/reference/libraries#client-libraries-install-nodejs,但我得到了完全相同的错误。然后我看到detectText已经取代了textDetection,但没有更多的成功

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-23 04:48:37

看起来您并没有像文档中描述的那样调用API。首先,看看文档中提供的sample code

代码语言:javascript
复制
const vision = require('@google-cloud/vision');

// Creates a client
const client = new vision.ImageAnnotatorClient();

/**
 * TODO(developer): Uncomment the following line before running the sample.
 */
// const fileName = 'Local image file, e.g. /path/to/image.png';

// Performs text detection on the local file
client
  .textDetection(fileName)
  .then(results => {
    const detections = results[0].textAnnotations;
    console.log('Text:');
    detections.forEach(text => console.log(text));
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

您必须首先创建一个ImageAnnotatorClient对象,作为您可以调用的textDetection()方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47946770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档