[Python] How to get good OCR results using pytesseract

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to get the data out of this image:

    [​IMG]

    and no matter what I try I can't get a good result.

    I have tried ImageEnhance and cv2 I got the most promising result using cv2 and adaptive Treshold:

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    inverted_image = cv2.bitwise_not(gray)
    #_, thresh = cv2.threshold(inverted_image ,95, 255, cv2.THRESH_BINARY)
    Test = cv2.adaptiveThreshold(inverted_image,120,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)


    Which gives me this picture:

    [​IMG]

    But tesseract doesn't seem to be able to "read it" I get the following output:

    text = pytesseract.image_to_string((Test), lang='fra')


    845 Vitalité

    75 lnteligence +

    35 Sagesse

    1Poñge 15 Dommages Feu AaTace à

    Teva eM
    ​

    text = pytesseract.image_to_string((Test), lang='eng')


    Extracted Text: 345 Vitalité

    ‘75 Inteligence ~

    ‘35 Sagesse

    “onée. 1S Dommages Feu WBTaole 2s

    7 Reve OM.
    ​

    Doesn't look much better. I also tried bluring it with cv2.GaussianBlur(image, (3, 3), 0) but that just makes it unreadable.

    I am missing something or doing something wrong?

    Whole project for better understanding: I want to create a kind of bot who reads the information on a part of my screen does some calculations and does a simple action. There exist around 40 different words that can be in the screenshot. Would it be a solution to create a Database with all words and do a pixel comparison? But how would I manage the numbers? I don't want to save all the numbers from 1-500.

    Any help is appreciated!

    Continue reading...

Compartilhe esta Página