node.js - TypeError:无法读取未定义的属性“ImageAnnotatorClient”
问题描述
我正在尝试使用 Google-cloud/vision 来检测图像中的手写文本识别,(pdf)。从过去 6 小时开始,我一直面临错误消息。如果我必须更改代码中的任何内容,请建议我。
'use strict';
function detectHandwritingOCR(fileName) {
const vision = require('@google-cloud/vision').v1p3beta1;
const fs = require('fs');
// Creates a client
const client = new vision.ImageAnnotatorClient();
const request = {
image: {
content: fs.readFileSync(fileName),
},
feature: {
languageHints: ['en-t-i0-handwrit'],
},
};
client
.documentTextDetection(request)
.then(results => {
const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(`Full text: ${fullTextAnnotation.text}`);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END vision_handwritten_ocr_beta]
}
console.log(detectHandwritingOCR('C:/Users/sandrpa/Downloads/handwrittenimage.jpg'));
我得到的错误信息是:
TypeError:无法读取未定义的属性“ImageAnnotatorClient”。**
解决方案
我试图复制这种情况;但是,我能够毫无问题地执行几乎完全相同的代码。我建议您验证您是否已安装最新的Vision Client 库版本,并在您的代码中明确指定身份验证凭据,以放弃任何身份验证问题。
'use strict';
function detectHandwritingOCR(fileName) {
const vision = require('@google-cloud/vision').v1p3beta1;
const fs = require('fs');
// Creates a client
const client = new vision.ImageAnnotatorClient({keyFilename: '<CREDENTIALS_FILE_NAME>.json'});
const request = {
image: {
content: fs.readFileSync(fileName),
},
feature: {
languageHints: ['en-t-i0-handwrit'],
},
};
client
.documentTextDetection(request)
.then(results => {
const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(`Full text: ${fullTextAnnotation.text}`);
})
.catch(err => {
console.error('ERROR:', err);
});
// [END vision_handwritten_ocr_beta]
}
console.log(detectHandwritingOCR('./<IMAGE_FILE_NAME>'));
推荐阅读
- javascript - 获取目标元素之后的所有元素id
- ios - .tag 在 Swift 4 中尝试 segue 3 个可能的值时不起作用
- sql - SQLite 慢选查询
- spring-boot - 无法解析值“${auth0.audience}”中的占位符“auth0.audience”
- angular - Angular mat-table 未显示数据,已修复,但不确定修复的原因
- javascript - 错误的(很可能)这个上下文
- r - 数据表中两列的常用条目
- sql - 设计问题:在 SQL 表中存储和检索增量的最佳方法
- kotlin - kotlin SQLite 数据库总是写默认值,从不写新值
- tensorflow - tfrecords 文件是否存在最佳元素数量?