首页 > 解决方案 > 有谁知道pytesseract的image_to_data,image_to_osd方法输出的含义?

问题描述

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

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

在此处输入图像描述

image_to_osd的输出如下所示。这里面的每个术语是什么意思?

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

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

标签: pythonocrpython-tesseract

解决方案


my_image.jpg

例如,在下面的代码中用 image_to_data 测试 my_image.jpg,我们会得到类似 results.png 的结果。

结果.png

  • level = 1/2/3/4/5,当前物品的等级。

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

  • block_num:当前物品的方块物品。tesseract OCR Image 时,会根据 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结果的含义:

  • 页码:当前项的页索引。在大多数情况下,图像只有一页。

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

  • Rotate:记录当前图片中的文字要转变成可读的角度,相对于当前图片顺时针旋转,取值范围为[0, 270, 180, 90]。与 [Orientation in degree] 值互补。

  • 方向置信度:表示当前[方向以度数]和[旋转]检测值的置信度。置信度越大,测试结果越可信,但目前尚未找到对其取值范围的解释。

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

  • 脚本置信度:当前图像中文本编码类型的置信度。

从 pytesseract 导入输出 导入 pytesseract 导入 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)

推荐阅读