运行 带 openjpeg2 的 tesseract 4.1 - 无法生成 pdf 输出

Running tesseract 4.1 with openjpeg2 - cannot produce pdf output

我已经在我的 RedHat 机器上安装了:

(py36_maw) [rvp@lib-archcoll box]$ tesseract -v
tesseract 4.1.0
 leptonica-1.78.0
  libjpeg 6b (libjpeg-turbo 1.2.90) : libpng 1.5.13 : libtiff 4.0.3 : zlib 1.2.7 : libopenjp2 2.3.1
 Found SSE

我尝试 运行 根据我能找到的文档生成 pdf 输出:

(py36_maw) [rvp@lib-archcoll box]$ time tesseract test.jp2 out -l eng PDF
read_params_file: Can't open PDF
Tesseract Open Source OCR Engine v4.1.0 with Leptonica
Warning: Invalid resolution 0 dpi. Using 70 instead.
Estimating resolution as 275

这需要 10 秒并生成文件 out.txt,其中 OCR 到文本的转换效果明显。

但是,它尝试读取一个名为 PDF 的文件,但我不知道如何获取 PDF 输出。

我阅读了各种文档,最有希望的似乎是建议编辑配置文件,但我能猜到的唯一文档是相关的,通过谷歌搜索 'tesseract 4.1 config',列出许多 'config' 变量名称,对于旧版本的 tesseract,但 none 似乎表明我可以指定生成 pdf 输出,更不用说 tesseract 4.1 了。

如何通过 CLI 调用 tesseract 4.1(使用 libopenjp2 2.3.1)从我的 jp2 输入文件生成 pdf 输出?奖励问题:我怎样才能让它在一个文件中同时生成 txt 和 pdf 输出 运行?

罗伯特

经过更多的浏览和挖掘,假设 reader 也做了一些并且知道 tesseract 使用 TESSDATA_PREFIX 是什么,这里是对我有用的步骤:

  1. 从以下位置下载 pdf.ttf 文件:https://github.com/tesseract-ocr/tesseract/blob/master/tessdata/pdf.ttf
  2. 将 pdf.ttf 复制到您的目录 $TESSDATA_PREFIX 并确保该变量已导出到您的 shell.
  3. 提示:使用命令:tesseract --print-parameters # 发现定义的变量名称,您可以在自己的配置文件中使用
  4. 使用 test.jp2 文件转到您的目录并使用这些行创建文件配置。
tessedit_create_pdf     1       Write .pdf output file
tessedit_create txt     1       Write .txt output file

(注意:或者您也可以将配置文件放在 TESSDATA_PREFIX 目录中,并使其始终为默认值。未测试。)

  1. 运行 在该目录中:

$ tesseract test.jp2 outputbase -l eng config

  1. 验证您的成功:它运行并生成文件 outputbase.txt 和 outputbase.pdf。 txt 文件看起来不错,可搜索的 pdf 在 pdf 查看器中看起来和工作正常,也就是说,您可以搜索和查找文本字符串。

希望这对其他人有帮助!