【发布时间】:2021-01-13 20:42:53
【问题描述】:
我想从python 的图像中提取文本。为此,我选择了pytesseract。当我尝试从图像中提取文本时,结果并不令人满意。我还浏览了this 并实现了列出的所有技术。然而,它似乎表现不佳。
图片:
代码:
import pytesseract
import cv2
import numpy as np
img = cv2.imread('D:\\wordsimg.png')
img = cv2.resize(img, None, fx=1.2, fy=1.2, interpolation=cv2.INTER_CUBIC)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1,1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
img = cv2.threshold(cv2.medianBlur(img, 3), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
txt = pytesseract.image_to_string(img ,lang = 'eng')
txt = txt[:-1]
txt = txt.replace('\n',' ')
print(txt)
输出:
t hose he large form might light another us should took mountai house n story important went own own thought girl over family look some much ask the under why miss point make mile grow do own school was
即使是 1 个不需要的空间也会让我付出很多代价。我希望结果是 100% 准确的。任何帮助,将不胜感激。谢谢!
【问题讨论】:
标签: python python-3.x ocr tesseract pytesser