Search code examples
pythonpython-imaging-librarytesseractpost-processing

How can i increase the accuracy of tesseract for this kind of image?


I am trying to get text from a video game using PIL and pytesseract. Here is an example of what I am trying to recognize :

enter image description here

I used a basic function to get binary image and another to invert it, here is the function :

@staticmethod
    def getBinaryImage(image, thresh):
        fn = lambda x: 255 if x > thresh else 0
        im = image.convert('L').point(fn, mode='1')
        return im

With these filters i manage to get this :

enter image description here

The problem is that tesseract can't recognize this. I tried with differents threshold for the binary image but it doesn't help.

My question is, is there any other basic filters i can apply to my image to make it better quality and make tesseract recognize it?

EDIT :

Here is a new version of my image, which was resized. But tesseract still can't recognize it.

enter image description here


Solution

  • I worked with tesseract and best way on OCR its train on your typography. Another ways u can perform solution its using parameters:

    --psm N
    Set Tesseract to only run a subset of layout analysis and assume a certain form of image. The options for N are:
    
    0 = Orientation and script detection (OSD) only.
    1 = Automatic page segmentation with OSD.
    2 = Automatic page segmentation, but no OSD, or OCR. (not implemented)
    3 = Fully automatic page segmentation, but no OSD. (Default)
    4 = Assume a single column of text of variable sizes.
    5 = Assume a single uniform block of vertically aligned text.
    6 = Assume a single uniform block of text.
    7 = Treat the image as a single text line.
    8 = Treat the image as a single word.
    9 = Treat the image as a single word in a circle.
    10 = Treat the image as a single character.
    11 = Sparse text. Find as much text as possible in no particular order.
    12 = Sparse text with OSD.
    13 = Raw line. Treat the image as a single text line,
         bypassing hacks that are Tesseract-specific.
    

    Then use --psm 10

    Another way its:

    --oem N
    Specify OCR Engine mode. The options for N are:
    
    0 = Original Tesseract only.
    1 = Neural nets LSTM only.
    2 = Tesseract + LSTM.
    3 = Default, based on what is available.
    

    This oem options are aviable on tesseract 4 and 5, in my experience i cant use this options cause errors I wanted to use --oem 0,so i installed tesseract 3.2, which its last version of --oem 0, and i get better predictions

    That my experience, try it. I hope it works for you.