【问题标题】:Recognize numbers from an image python从图像python中识别数字
【发布时间】:2020-03-08 10:42:58
【问题描述】:

我正在尝试从游戏截图中提取数字。

我正在尝试提取:

98
3430
5/10

from PIL import Image
import pytesseract 
image="D:/img/New folder (2)/1.png"
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
text = pytesseract.image_to_string(Image.open(image),lang='eng',config='--psm 5')
print(text)

输出是乱码

‘t hl) keteeeees
ek pSlaerenen
JU) pgrenmnreserenny
Rates B
d dali eas. 5
cle aM (Sores
|, S| pgranmrerererecons
a cee 3
pea 3
oS :
(geo eenee
ey
=
es A

【问题讨论】:

  • 可以上传图片吗?
  • 您将需要一个更强大的预处理管道才能正确检测数字。您必须尽可能清晰地分割字符,此外,文本已变形,您需要将其解开。

标签: python opencv tesseract


【解决方案1】:

好的,所以我尝试将其更改为灰度、反向对比度或使用不同的阈值,但这一切似乎都相当不准确。 问题似乎是倾斜和较小的数字。你碰巧没有任何高清图像吗? 我能得到的最准确的是以下代码。

import cv2
import pytesseract
import imutils

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread('D:/img/New folder (2)/1.png') #test.png is your original image
img = imutils.resize(img, width=1400)
crop = img[340:530, 100:400]

data = pytesseract.image_to_string(crop,config=' --psm 1 --oem 3  -c tessedit_char_whitelist=0123456789/')
print(data)

cv2.imshow('crop', crop)
cv2.waitKey()

否则我推荐其中一种方法为described in the similar questionthis one.

【讨论】:

    【解决方案2】:

    如果文字被设计包围,则tesseract会受到很大影响

    tesseract 的 insted 尝试在 opencv 中使用 findcontours(经过少许模糊、膨胀)

    你会得到边界框,然后它可能也会覆盖该文本

    【讨论】:

      猜你喜欢
      • 2015-06-27
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2013-02-16
      相关资源
      最近更新 更多