我正在尝试使用
pytesseract
从图像中提取数据。该模块有 image_to_data
和 image_to_osd
方法。这两种方法提供了大量信息(TextLineOrder
、WritingDirection
、ScriptDetection
、Orientation
等)作为输出。
下图是
image_to_data
方法的输出。这些列的值 (level
、block_num
、par_num
、line_num
、word_num
) 的含义是什么?
image_to_osd的输出如下所示。其中每个术语的含义是什么?
Page number: 0
Orientation in degrees: 0
Rotate: 0
Orientation confidence: 16.47
Script: Latin
Script confidence: 4.00
我参考了文档,但没有找到有关这些参数的任何信息。
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)
级别:
block_num:检测到的文本或项目的块号
列
par_num:检测到的文本或项目的段落编号
列
line_num:检测到的文本或项目的行号
列
word_num:检测到的文本或项目的字数
查看下图以供参考。