<!DOCTYPE html>
<html>
<head>
  <meta charset='UTF-8'>
  <title>Electron Tesseract.js Example</title>
  <script src='https://cdn.jsdelivr.net/npm/tesseract.js@2.1.1'></script>
  <script>
    const Tesseract = require('tesseract.js');
<pre><code>// 本地语言包的相对路径
const langPath = './tessdata';

Tesseract.recognize('https://tesseract.projectnaptha.com/img/eng_bw.png', 'eng', { 
  langPath: langPath 
})
  .then(function(result) {
    console.log(result.text);
  })
  .catch(function(error) {
    console.error(error);
  });
</code></pre>
  </script>
</head>
<body>
  <h1>Electron Tesseract.js Example</h1>
</body>
</html>
<p>在上面的例子中,我们将 <code>langPath</code> 设置为 <code>'./tessdata'</code>,表示语言包文件夹在与 HTML 文件相同的目录下。你可以根据实际情况更改 <code>langPath</code> 的路径来引用你的本地语言包文件夹。</p>
Electron 中使用 Tesseract.js 引用本地语言包

原文地址: https://www.cveoy.top/t/topic/qeWG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录