Node.js Firebase云功能&;Cloud Vision API:TypeError:Vision.detectText不是函数
我尝试在Firebase云函数中使用Cloud Vision API来OCR存储在Firebase存储中的图像 我导入GoogleCloudVision客户端库如下Node.js Firebase云功能&;Cloud Vision API:TypeError:Vision.detectText不是函数,node.js,firebase,google-cloud-functions,google-cloud-vision,Node.js,Firebase,Google Cloud Functions,Google Cloud Vision,我尝试在Firebase云函数中使用Cloud Vision API来OCR存储在Firebase存储中的图像 我导入GoogleCloudVision客户端库如下 const vision = require('@google-cloud/vision'); 然后我打电话 vision.detectText({ source: { imageUri: 'gs://xxxx.appspot.com/yyyy.JPG' } }) 然而,我得到了一个错误 TypeError:vision.de
const vision = require('@google-cloud/vision');
然后我打电话
vision.detectText({ source: { imageUri: 'gs://xxxx.appspot.com/yyyy.JPG' } })
然而,我得到了一个错误
TypeError:vision.detectText不是函数
最初我用
vision.textDetection({ source: { imageUri: ... } })
从这个例子中,我得到了完全相同的错误。然后我读到,textDetection已经被detectText取代,但不再成功
提前感谢您似乎没有按照文档所述调用API。首先,看一下文档中提供的:
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);
});
您必须首先创建一个对象,作为您可以调用的方法。@RenaudT如果此答案正确,请将其作为正确答案接受。