tesseract 根本不准确,即使有配置

tesseract not accurate at all, even with config

我的代码⠀

for index, img in enumerate(data): # data is list of base64 decoded strings
    b64 = base64.b64decode(bytes(img[22:], encoding='utf-8'))
    raw = BytesIO(b64)
    im = Image.open(raw).convert('LA')
    pixels = im.load()
    width, height = im.size
    for x in range(width):
        for y in range(height):
            if pixels[x, y][0] > 100: pixels[x, y] = (255, 255)
            else: pixels[x, y] = (0, 255)
    print(pytesseract.image_to_string(im, config='tessedit_char_whitelist=1234567890plus?'))

我的形象:

输出:
Te Ys
⠀ 我可以做些什么来让它变得更好,我尝试使用从 0 到 13 的每个 psm 和配置键中的 -c 标志⠀⠀

您需要反转图像。那就准了。

import pytesseract
import cv2

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

image = cv2.imread('addition.png', 0)
image = 255 - image

for psm in range(6,13+1):
    config = '--oem 3 --psm %d' % psm
    txt = pytesseract.image_to_string(image, config = config, lang='eng')
    print('psm ', psm, ':',txt)

这对所有 psm 值都给出了良好的结果

psm  6 : 18 plus 16?
psm  7 : 18 plus 16?
psm  8 : 18 plus 16?
psm  9 : 18 plus 16?
psm  10 : 18 plus 16?
psm  11 : 18 plus 16?
psm  12 : 18 plus 16?
psm  13 : 18 plus 16?