Reading text from image

怎甘沉沦 提交于 2019-12-06 02:02:54

问题


Any suggestions on converting these images to text? I'm using pytesseract and it's working wonderfully in most cases except this. Ideally I'd read these numbers exactly. Worst case I can just try to use PIL to determine if the number to the left of the '/' is a zero. Start from the left and find the first white pixel, then

from PIL import Image
from pytesseract import image_to_string

myText = image_to_string(Image.open("tmp/test.jpg"),config='-psm 10')
myText = image_to_string(Image.open("tmp/test.jpg"))

The slash in the middle causes issues here. I've also tried using PIL's '.paste' to add lots of extra black around the image. There might be a few other PIL tricks I could try, but i'd rather not go that route unless I have to.

I tried using config='-psm 10' but my 8's were coming through as ":" sometimes, and random characters other times. And my 0's were coming through as nothing.

Reference to: pytesseract don't work with one digit image for the -psm 10

_____________EDIT_______________ Additional samples:

1BJ2I]

DIS

10.I'10

20.I20

So I'm doing some voodoo conversions that seem to be working for now. But looks very error prone:

def ConvertPPTextToReadableNumbers(text):
    text = RemoveNonASCIICharacters(text)
    text = text.replace("I]", "0")
    text = text.replace("|]", "0")
    text = text.replace("l]", "0")
    text = text.replace("B", "8")
    text = text.replace("D", "0")
    text = text.replace("S", "5")
    text = text.replace(".I'", "/")
    text = text.replace(".I", "/")
    text = text.replace("I'", "/")
    text = text.replace("J", "/")
    return text

Ultimately generates:

ConvertPPTextToReadableNumbers return text =  18/20
ConvertPPTextToReadableNumbers return text =  0/5
ConvertPPTextToReadableNumbers return text =  10/10
ConvertPPTextToReadableNumbers return text =  20/20

回答1:


Generally speaking, most OCR tools (like Tesseract) are tuned for working with high-resolution scans of printed text. They do not perform well on low-resolution or pixellated images.

Two possible approaches here are:

  1. If the font, background, and layout of your images are completely predictable, you don't need Tesseract at all; it's just complicating matters. Build a library of images representing each character you need to recognize, and check whether parts of the image are equal to the reference image.

  2. If that isn't an option, or if it seems too hard, you could upscale the pixellated image using one of the hq*x algorithms. The added detail may be sufficient to get Tesseract to reliably recognize the characters.



来源:https://stackoverflow.com/questions/39218106/reading-text-from-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!