tesseract 命令大全

本文介绍了 Tesseract OCR 工具的使用方法,包括如何指定语言、配置文件路径、页面分割模式及 OCR 引擎模式等高级选项。适用于希望提高 OCR 文档识别准确性的开发者。

Usage:
  tesseract --help | --help-extra | --help-psm | --help-oem | --version
  tesseract --list-langs [--tessdata-dir PATH]
  tesseract --print-parameters [options...] [configfile...]
  tesseract imagename|imagelist|stdin outputbase|stdout [options...] [configfile
...]

OCR options:
  --tessdata-dir PATH   Specify the location of tessdata path.
  --user-words PATH     Specify the location of user words file.
  --user-patterns PATH  Specify the location of user patterns file.
  -l LANG[+LANG]        Specify language(s) used for OCR.
  -c VAR=VALUE          Set value for config variables.
                        Multiple -c arguments are allowed.
  --psm NUM             Specify page segmentation mode.
  --oem NUM             Specify OCR Engine mode.
NOTE: These options must occur before any configfile.

Page segmentation modes:
  0    Orientation and script detection (OSD) only.
  1    Automatic page segmentation with OSD.
  2    Automatic page segmentation, but no OSD, or OCR.
  3    Fully automatic page segmentation, but no OSD. (Default)
  4    Assume a single column of text of variable sizes.
  5    Assume a single uniform block of vertically aligned text.
  6    Assume a single uniform block of text.
  7    Treat the image as a single text line.
  8    Treat the image as a single word.
  9    Treat the image as a single word in a circle.
 10    Treat the image as a single character.
 11    Sparse text. Find as much text as possible in no particular order.
 12    Sparse text with OSD.
 13    Raw line. Treat the image as a single text line,
       bypassing hacks that are Tesseract-specific.

OCR Engine modes:
  0    Legacy engine only.
  1    Neural nets LSTM engine only.
  2    Legacy + LSTM engines.
  3    Default, based on what is available.

Single options:
  -h, --help            Show minimal help message.
  --help-extra          Show extra help for advanced users.
  --help-psm            Show page segmentation modes.
  --help-oem            Show OCR Engine modes.
  -v, --version         Show version information.
  --list-langs          List available languages for tesseract engine.
  --print-parameters    Print tesseract parameters.

Tesseract-OCR 是一个开源的光学字符识别(OCR)引擎,支持多种语言。它可以通过命令行进行操作,适用于图像文件中的文本提取。以下是 Tesseract-OCR 的命令行使用教程。 ### 基本语法 Tesseract-OCR 的基本命令格式如下: ``` tesseract [输入图像文件] [输出文件前缀] [-l lang] [-psm pagesegmode] [configfile...] ``` - **输入图像文件**:指定要处理的图像文件路径。 - **输出文件前缀**:指定输出文件的名称前缀,Tesseract 会自动生成 `.txt` 文件。 - **-l lang**:指定使用的语言包,例如 `eng` 表示英文,`chi_sim` 表示简体中文。 - **-psm pagesegmode**:指定页面分割模式,用于控制如何分割图像中的文本区域。 - **configfile...**:可选配置文件,用于调整 OCR 引擎的行为。 ### 示例命令 #### 英文识别 如果需要对一张英文图片进行识别,可以使用以下命令: ``` tesseract test.png output_1 -l eng ``` 此命令将 `test.png` 图像文件中的英文文本识别并保存到 `output_1.txt` 文件中[^2]。 #### 中文识别 对于简体中文的识别,需要确保已经安装了中文语言包,并使用以下命令: ``` tesseract picture.tif test -l chi_sim ``` 该命令会对 `picture.tif` 文件中的简体中文进行识别,并将结果保存到 `test.txt` 文件中[^3]。 ### 页面分割模式(PSM) Tesseract 提供了多种页面分割模式,通过 `-psm` 参数可以指定不同的模式。常见的几种模式包括: - **0**: 自动选择页面分割模式。 - **1**: 将整个图像视为一页文本。 - **3**: 完全自动页面分割,不考虑文本方向。 - **6**: 假设图像是一段纯文本。 例如,若希望以完全自动页面分割模式进行识别,可以使用以下命令: ``` tesseract image.jpg output -l eng -psm 3 ``` ### 多语言识别 如果需要同时识别多种语言,可以通过 `-l` 参数指定多个语言包,用加号连接。例如,同时识别英文和中文: ``` tesseract mixed_text_image.jpg output -l eng+chi_sim ``` ### 配置文件 Tesseract 支持通过配置文件来调整 OCR 的行为,例如设置特定的参数或优化某些场景下的识别效果。配置文件通常位于安装目录下的 `tessdata/configs` 文件夹中。例如,若需要使用 `batch.nochop` 配置文件,可以这样调用: ``` tesseract input.tif output -l eng batch.nochop ``` ### 环境变量配置 为了方便在任意位置调用 Tesseract,可以将其安装路径添加到系统环境变量 `PATH` 中。完成配置后,在命令行工具中输入 `tesseract`,如果显示用法信息,则表示安装成功[^5]。 ### 测试安装 在终端或命令行工具中输入以下命令,测试 Tesseract 是否正常工作: ``` tesseract ``` 如果出现类似以下的用法提示,则说明安装成功: ``` Usage: tesseract --help | --help-extra | --version | --list-langs | ... ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值