Pytesseract无法读取屏幕截图上的数字

问题描述 投票:0回答:1

您好,为什么pytesseract无法读取此数字,我的结果是:cre

Screenshot

pytesseract.pytesseract.tesseract_cmd = "C:\\Users\\X\\AppData\\Local\\Tesseract-OCR\\tesseract.exe"
im = pyautogui.screenshot(region=(265, 110, 50, 20))
im.save("screenshot.png")
print(pytesseract.image_to_string(Image.open("screenshot.png")))

任何人都知道我可以如何改善结果?

python image ocr python-tesseract
1个回答
1
投票

您应该在运行Tesseract之前对图像进行预处理(带有opencv库的python代码):


    import cv2

    pytesseract.pytesseract.tesseract_cmd = "C:\\Users\\X\\AppData\\Local\\Tesseract-OCR\\tesseract.exe"
    im = pyautogui.screenshot(region=(265, 110, 50, 20))
    im= cv2.bitwise_not(im)
    im.save("screenshot.png")
    print(pytesseract.image_to_string(Image.open("screenshot.png")))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.