我尝试在Firebase Cloud function中使用Cloud Vision API来OCR存储在Firebase Storage中的图像。
我导入Google Cloud vision客户端库,如下所示
const vision = require('@google-cloud/vision');然后我会打电话给
vision.detectText({ source: { imageUri: 'gs://xxxx.appspot.com/yyyy.JPG' } }) 但是,我得到了一个错误
TypeError: vision.detectText不是函数
最初我用的是
vision.textDetection({ source: { imageUri: ... } })从这个例子中,https://cloud.google.com/vision/docs/reference/libraries#client-libraries-install-nodejs,但我得到了完全相同的错误。然后我看到detectText已经取代了textDetection,但没有更多的成功
提前感谢
发布于 2017-12-23 04:48:37
看起来您并没有像文档中描述的那样调用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()方法。
https://stackoverflow.com/questions/47946770
复制相似问题