Функция pytesseract image_to_string вообще не точна

Мой код

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
Что я могу сделать, чтобы сделать это лучше, я пытался использовать все psm от 0 до 13 и флаг -c в конфигурации


person Ozballer31    schedule 10.08.2020    source источник
comment
помощь все еще нужна   -  person Ozballer31    schedule 11.08.2020
comment
дайте немного отступы к изображению.   -  person Tarun Chakitha    schedule 14.08.2020
comment
Вы пробовали простое пороговое значение?   -  person Tarun Chakitha    schedule 14.08.2020


Ответы (1)


Этот код работал нормально для меня, но пробелы не были обнаружены.

    img = ~cv2.imread("18.png",0)
    rows,cols = img.shape[:2]
    # M = np.float32([[1,0,25],[0,1,15]])
    # img = cv2.warpAffine(img,M,(cols*2,rows*2),borderValue=(255,255,255))
    custom_oem_psm_config = r'--oem 3 --psm 3 -c tessedit_char_whitelist="1234567890plus?"'# -c preserve_interword_spaces=1'
    print(pytesseract.image_to_string(img,config=custom_oem_psm_config))

Выход:

18plus16?
person Tarun Chakitha    schedule 14.08.2020