Tru*_*ran 1 python ocr python-tesseract
当我使用 Pytesseract 识别该图像中的文本时,Pytesseract 返回7A51k但该图像中的文本是7,451k。
如何使用代码解决此问题而不是提供更清晰的源图像?
我的代码
import pytesseract as pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = 'D:\\App\\Tesseract-OCR\\tesseract'
img = Image.open("captured\\amount.png")
string = pytesseract.image_to_string(image=img, config="--psm 10")
print(string)
Run Code Online (Sandbox Code Playgroud)
我有一个两步解决方案
当您读取阈值图像时:
7,451k
Run Code Online (Sandbox Code Playgroud)
代码:
import cv2
from pytesseract import image_to_string
img = cv2.imread("4ARXO.png")
(h, w) = img.shape[:2]
img = cv2.resize(img, (w*3, h*3))
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.threshold(gry, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
txt = image_to_string(thr)
print(txt)
Run Code Online (Sandbox Code Playgroud)