Detection of the word working randomly

55 views
Skip to first unread message

TroTro

unread,
Nov 4, 2023, 2:48:25 PM11/4/23
to tesseract-ocr
Hi everyone,

I am a begginer of python and I start a project for myself. This project is for Pokemon games, and i need to get the name of pokemon i am fighting against. 
The problem is that sometimes it works very well and if i try another time it detects the empty string.
For instance, this is the picture i capture to extract the pokemon name. It should extract "cadoizo" and even if it is not accurate, I coded something to select the most similar pokemon name. 
I just don't want an empty string. Do you have some solution? 

That's the part of my code doing it:


# Spécifiez les coordonnées de la région de l'écran à capturer (x, y, hauteur, largeur)
region = (300, 70, 280, 68)
screenshot = pyautogui.screenshot(region=region)

# Convertissez la capture d'écran en une image Pillow
image = Image.frombytes("RGB", screenshot.size, screenshot.tobytes())
image.show()

# Utilisez pytesseract pour extraire du texte de l'image
text = pytesseract.image_to_string(image)
morceaux = text.split(' ', 1)
text = morceaux[0]
# Affichez le texte extrait
print("Texte extrait de l'image:", text)
pokemon name.png
Reply all
Reply to author
Forward
0 new messages