I need to extract text from various screenshot, this is the code I'm using right now:
from PIL import Image
from pytesseract import pytesseract
path_to_tesseract = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
image_path = r"screenshot_5850.jpg"
img = Image.open(image_path)
pytesseract.tesseract_cmd = path_to_tesseract
text = pytesseract.image_to_string(img, lang="ita")
print(text)
My problem is that the result I'm getting is not accurate at all, and I think the problem is the background of my image: the text I'm interested in is always white with black border, but the background change in every screenshot and can be various colours. These are a couple of examples of the image I'm working with:
How can I improve my code? thank you all

