node.js - Firebase Cloud 函数和 Cloud Vision API : TypeError: vision. detectorText 不是函数

标签 node.js firebase google-cloud-functions google-cloud-vision

我尝试使用 Firebase Cloud 函数中的 Cloud Vision API 对 Firebase 存储中存储的图像进行 OCR。

我按如下方式导入 Google Cloud 视觉客户端库

const vision = require('@google-cloud/vision');

然后我打电话

vision.detectText({ source: { imageUri: 'gs://xxxx.appspot.com/yyyy.JPG' } }) 

但是我收到错误

类型错误:vision.detectText 不是函数

最初我使用

vision.textDetection({ source: { imageUri: ... } })

从此示例 https://cloud.google.com/vision/docs/reference/libraries#client-libraries-install-nodejs但我得到了完全相同的错误。然后我读到 textDetection 已被 detectorText 取代,但没有再成功

提前致谢

最佳答案

您似乎没有按照记录调用 API。首先,看一下sample code文档中提供:

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()您可以调用的方法。

关于node.js - Firebase Cloud 函数和 Cloud Vision API : TypeError: vision. detectorText 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47946770/

相关文章:

java - Firebase 数据库值不断变化而不是自行添加

python - 在 Python Cloud Function 中使用 errorhandler 返回 JSON

google-cloud-platform - 使用来自上一步的 Json 对象的云工作流 firestore 连接器在 Firestore 中插入数据时出现问题,这是一个云函数

ios - Node.JS RESTful API 的最佳身份验证方法

node.js - 在 wsl 2 中安装不同的 Node 版本

firebase - Jest Test - 当前环境不支持指定的持久化类型

firebase - 为什么 functions.config() 返回 {}?

javascript - multer如何确定file.mimetype的值

javascript - NodeJS - 如何向 MySQL 插入多行

android - 无法使用 firebase 身份验证模块注册