【问题标题】:Pytesseract fails to recognize digits from imagePytesseract 无法识别图像中的数字
【发布时间】:2019-09-05 01:37:51
【问题描述】:

Pytesseract 无法识别数字 68。它识别

  • 65
  • 55
  • 38
  • 88
  • Oct0c:0::
  • WedMen

使用的脚本:

config= "-c tessedit_char_whitelist=01234567890.:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -psm 3 -oem 0"
text = pytesseract.image_to_string(image, config=config)

也尝试使用 1-12 中的不同 psm 编号,但没有运气。增加对比度会导致更多数字无法识别:

kernel = np.ones((2,2),np.uint8)
dilation = cv2.dilate(im, kernel)#,iterations = 1)
text = pytesseract.image_to_string(dilation, config=config)

原始数据:

运行脚本后:

运行新脚本后:

【问题讨论】:

  • 不,调整图像大小。使用cv.resize。检查你的大写字母有多少像素高,然后计算要缩放多少图像以使它们大约 50 像素高。

标签: python opencv image-processing ocr python-tesseract


【解决方案1】:

在将图像放入 Pytesseract 之前进行一些预处理以清理/平滑图像会有所帮助。具体来说,关闭小孔和去除噪声的形态学操作可以增强图像。应用锐化滤镜也可能有所帮助。调整内核大小或类型也可能会有所帮助。我相信--psm 6 是这里最好的,因为图像是一个统一的文本块。这是我在简单的变形关闭后得到的结果

import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

image = cv2.imread('1.png',0)
thresh = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY_INV)[1]

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
result = 255 - close

data = pytesseract.image_to_string(result, lang='eng',config='--psm 6')
print(data)

cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.imshow('close', close)
cv2.waitKey()

【讨论】:

  • 嗨@nathancy,不知道为什么我的结果不一样。复制了确切的代码但结果如下,将在问题中附上照片:在 Date Total mrm morn mu 0:: Va( am New Aunt Depart 705211 'Mvl rm Rooms 'M41 Trot Room Revenu: Avg Rate 25 520有 104 1 103 3 100 — — — — 100 97 95 3 3 3 9 147 77 3 049 25 25 520 TM 104 1 103 3 100 — — — — 100 97 95 3 3 3 9 147 77 3 049 104 27 520 FM 1 103 3 100 — — — 1 101 90 97 2 2 2 5 203 23 3 101 52 2
  • 如果将jpg转为png,已经有转为png无法挽回的损失。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多