Tesseract ocr输出,在检测到的文本之间包含单个字符

2024-09-28 05:21:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Tesseract从下图中提取

enter image description here

text = pytesseract.image_to_string(image, config='-c preserve_interword_spaces=1 --psm 1 --oem 1')

这是tesseract 4 ocr的结果

print(text)

Wrote Datastream application 
e Used Kafka to get the accounts

如果您看到图像中的项目符号被转换为e,我在文档中发现了几个这样的点,它们被转换为ascii中的单个字符

如果有人熟悉此类问题并有解决方案,请告诉我


Tags: totextimageconfigstringocrspacesprint
1条回答
网友
1楼 · 发布于 2024-09-28 05:21:50

我有一个建议,也许最好去掉要点

  • 删除项目符号的一个解决方案是应用adaptive-threshold

  • 如果我们将adaptive-threshold应用于当前图像:

    • enter image description here
  • 现在如果我们读到它:

    • Wrote Datastream application |
      Used Kafka to get the accounts
      
      

代码:


import cv2
import pytesseract

img = cv2.imread("4XMue.png")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.adaptiveThreshold(gry, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                            cv2.THRESH_BINARY, 11, 131)
txt = pytesseract.image_to_string(thr)
print(txt)

请允许我告诉您,我的示例代码可能不适用于所有图像。因为图像可能有不同的伪影或需要额外的处理。您可能需要更改adaptive-thresholdblock-sizeC参数。因此,请先阅读adaptive-threshold

相关问题 更多 >

    热门问题