我有一个这样的二进制图像,

我想在Python中使用tesseract ocr提取图像中的数字。我在图像上这样使用了pytesseract,
txt = pytesseract.image_to_string(img)但是我没有得到任何好的结果。
我可以在预处理或增强中做些什么来帮助tesseract做得更好?
我尝试使用East Text Detector对图像中的文本进行本地化,但它无法识别文本。
如何在python中进行此操作?
发布于 2020-12-06 02:59:34
我认为页面分割模式是这里的一个重要因素。
由于我们正在尝试读取列值,因此可以使用--psm 4 (source)
import cv2
import pytesseract
img = cv2.imread("k7bqx.jpg")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
txt = pytesseract.image_to_string(gry, config="--psm 4")我们想让文本以#开头
txt = sorted([t[:2] for t in txt if "#" in t])结果:
['#3', '#7', '#9', '#€']但是我们错过了4,5,我们可以应用adaptive-thresholding

结果:
['#3', '#4', '#5', '#7', '#9', '#€']不幸的是,#2和#6不被识别。
代码:
import cv2
import pytesseract
img = cv2.imread("k7bqx.jpg")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.adaptiveThreshold(gry, 252, cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY_INV, blockSize=131, C=100)
bnt = cv2.bitwise_not(thr)
txt = pytesseract.image_to_string(bnt, config="--psm 4")
txt = txt.strip().split("\n")
txt = sorted([t[:2] for t in txt if "#" in t])
print(txt)https://stackoverflow.com/questions/56237858
复制相似问题