【问题标题】:"Error: Failed to detect OS" with Node.js on VS Code“错误:无法检测操作系统”在 VS Code 上使用 Node.js
【发布时间】:2020-04-24 20:07:26
【问题描述】:

我正在使用 tesseract.js 进行 OCR,但是当我更改 exampleImage 时,我得到了这个错误。我根本找不到有关此错误的任何信息。提前谢谢你。

app.js

const exampleImage = 'https://d1q6f0aelx0por.cloudfront.net/product-logos/5431a80b-9ab9-486c-906a-e3d4b5ccaa96-hello-world.png';
const Tesseract=require('tesseract.js');
const worker = Tesseract.createWorker({
  logger: m => console.log(m)
});
Tesseract.setLogging(true);
work();

async function work() {
  await worker.load();
  await worker.loadLanguage('eng');
  await worker.initialize('eng');

  let result = await worker.detect(exampleImage);
  console.log(result.data);

  result = await worker.recognize(exampleImage);
  console.log(result.data);

  await worker.terminate();
}

控制台日志

Error: Failed to detect OS
    at ChildProcess.<anonymous> (c:\Users\jorda\AppData\Local\Programs\Microsoft VS Code\bin\Example\node_modules\tesseract.js\src\createWorker.js:173:15)
    at ChildProcess.emit (events.js:311:20)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)

【问题讨论】:

    标签: javascript node.js error-handling ocr tesseract


    【解决方案1】:

    您的使用情况和他们的文档用例不匹配您检查过他们的文档吗?

    例如,试着像他们一样写作;

    const { createWorker } = require('tesseract.js');
    const exampleImage = 'https://d1q6f0aelx0por.cloudfront.net/product-logos/5431a80b-9ab9-486c-906a-e3d4b5ccaa96-hello-world.png';
    
    const worker = createWorker({
      logger: m => console.log(m), // Add logger here
    });
    
    (async () => {
      await worker.load();
      await worker.loadLanguage('eng');
      await worker.initialize('eng');
      const { data: { text } } = await worker.recognize(exampleImage);
      console.log(text);
      await worker.terminate();
    })();
    

    【讨论】:

      【解决方案2】:

      没关系,我使用的图片太小了。使用更大的图像,代码运行良好。

      【讨论】:

        猜你喜欢
        • 2019-01-19
        • 1970-01-01
        • 1970-01-01
        • 2019-10-04
        • 1970-01-01
        • 2012-02-05
        • 2014-06-25
        • 2014-04-14
        • 2011-05-21
        相关资源
        最近更新 更多