有人知道 pytesseract 中 image_to_data 和 image_to_osd 方法的输出含义吗?

8

我正在使用pytesseract从图像中提取数据。这个模块有image_to_dataimage_to_osd方法。这两种方法提供了很多信息(TextLineOrder,WritingDirection,ScriptDetection,Orientation等)作为输出。

下面的图片是image_to_data方法的输出。这些列(level, block_num, par_num, line_num, word_num)的值代表什么意思?

enter image description here

image_to_osd的输出如下。每个术语都代表什么含义?

页码:0 度数方向:0 旋转:0 方向置信度:16.47 脚本:拉丁文 脚本置信度:4.00

我查阅了文档,但没有找到任何有关这些参数的信息。

2个回答

13

my_image.jpg

例如,在以下代码中使用 image_to_data 测试 my_image.jpg,我们将获得类似于 results.png 的结果。

results.png

  • level = 1/2/3/4/5,当前项目的级别。

  • page_num: 当前项目的页面索引。在大多数情况下,一张图片只有一页。

  • block_num: 当前项目的块编号。对于 tesseract OCR 图像,它会根据 PSM 参数和一些规则将图像分成几个块。一行中的单词通常位于一个块中。

  • par_num: 当前项目的段落索引。它是页面分析结果。line_num: 当前项目的行索引。它是页面分析结果。word_num: 一个块中的单词索引。

  • line_num: 当前项目的行索引。它是页面分析结果。

  • word_num: 一个块中的单词索引。

  • left/top/width/height:当前单词的左上坐标以及它的宽度和高度。

  • conf: 当前单词的置信度,范围为-1~100。-1表示这里没有文本。100是最高值。

  • text: 单词的 OCR 结果。

来自 image_to_osd 的结果含义:

  • Page number: 当前项目的页面索引。在大多数情况下,一张图片只有一页。

  • Orientation in degrees: 当前图像中文本相对于其阅读角度的顺时针旋转角度,值范围为[0、270、180、90]。

  • Rotate: 记录将当前图像中的文本转换为可读文本所需的角度,相对于当前图像的顺时针旋转,值范围为[0、270、180、90]。与 [Orientation in degrees] 值互补。

  • Orientation confidence: 表示当前 [Orientation in degrees] 和 [Rotate] 检测值的置信度。置信度越大,测试结果越可靠,但目前尚未找到其值范围的解释。

  • Script: 当前图片中文本的编码类型。

  • Script confidence: 当前图片中文本编码类型的置信度。

from pytesseract import Output import pytesseract import cv2

image = cv2.imread("my_image.jpg")

#swap color channel ordering from BGR (OpenCV’s default) to RGB (compatible with Tesseract and pytesseract).
# By default OpenCV stores images in BGR format and since pytesseract assumes RGB format,
# we need to convert from BGR to RGB format/mode:
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
 
pytesseract.pytesseract.tesseract_cmd = r'C:\mypath\tesseract.exe'
custom_config = r'-c tessedit_char_whitelist=0123456789 --psm 6'
results = pytesseract.image_to_data(rgb, output_type=Output.DICT,lang='eng',config=custom_config)
print(results)

6

级别:

  1. 没有 block_num、paragraph_num、line_num 和 word_num 的项目
  2. 具有 block_num,但没有 paragraph_num、line_num 和 word_num 的项目
  3. 具有 block_num 和 paragraph_num,但没有 line_num 和 word_num 的项目
  4. 具有 block_num、paragraph_num 和 line_num,但没有 word_num 的项目
  5. 具有所有这些数字的项目

block_num: 检测到的文本或项目的块编号
par_num: 检测到的文本或项目的段落编号
line_num: 检测到的文本或项目的行号
word_num: 检测到的文本或项目的单词编号

但是以上 4 列是相互关联的。如果项目来自新行,则单词编号将从 0 开始重新计数,而不是从上一行的最后一个单词编号继续。行号、段落编号和块编号也是如此。

请参考下面的图像。
第一列: 块编号
第二列: 段落编号
第三列: 行号
第四列: 单词编号
enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接