【发布时间】:2021-12-30 11:01:39
【问题描述】:
我正在使用 Google Cloud Vision 检测图像上的文本。这在大约 80% 的时间里都有效。另外 20%,我得到这个错误:
Error: 3 INVALID_ARGUMENT: Request must specify image and features.
at Object.callErrorFromStatus (C:\Users\emily\workspace\bot\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
at Object.onReceiveStatus (C:\Users\emily\workspace\bot\node_modules\@grpc\grpc-js\build\src\client.js:180:52)
at Object.onReceiveStatus (C:\Users\emily\workspace\bot\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:336:141)
at Object.onReceiveStatus (C:\Users\emily\workspace\bot\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
at C:\Users\emily\workspace\bot\node_modules\@grpc\grpc-js\build\src\call-stream.js:160:78
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 3,
details: 'Request must specify image and features.',
metadata: Metadata { internalRepr: Map(0) {}, options: {} },
note: 'Exception occurred in retry method that was not classified as transient'
当我在谷歌上搜索这个问题时,似乎我需要在我的请求中发送特定的标头来解决这个问题,基本上就像这里指定的那样:https://cloud.google.com/vision/docs/ocr#specify_the_language_optional
但是,我不知道如何使用我正在使用的 Node.js 代码发送这些请求参数,而且我在任何地方都找不到任何示例。有人可以帮我弄清楚如何使用它吗?我目前的代码是这样的:
// Performs text detection on the image file using GCV
(async () => {
await Jimp.read(attachment.url).then(image => {
return image
.invert()
.contrast(0.5)
.brightness(-0.25)
.write('temp.png');
});
const [result] = await googleapis.textDetection('temp.png');
const fullImageResults = result.textAnnotations;
谢谢!
【问题讨论】:
-
云视觉有一个单独的 npm 模块,github.com/googleapis/nodejs-vision。请参考此页面,您可以使用此库向视觉 api 发出请求。这是一些用于图像文本检测的示例代码,github.com/googleapis/nodejs-vision/blob/main/samples/…。
标签: node.js ocr google-cloud-vision