改进 tesseract 检测

Improving the tesseract detection

我尝试使用 Tesseract 从此图像中提取文本。

我试过的代码:

img = Image.open('downloadedpng.jpeg').convert('L')
ret,img = cv2.threshold(np.array(img), 125, 255, cv2.THRESH_BINARY)
img = Image.fromarray(img.astype(np.uint8))
print(pytesseract.image_to_string(img))

我得到的输出: re vie
我已经尝试使用以下代码进行腐蚀和膨胀:

img_erosion = cv2.erode(img, kernel, iterations=1)
img_dilation = cv2.dilate(img, kernel, iterations=1)

但我遇到了错误。 知道如何将其正确转换为字符串吗?

为了获得最佳效果,您应该传递白底黑字:

import cv2
from PIL import Image

img = cv2.imread('1.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.bitwise_not(img) # <- invert
ret, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)
im = Image.fromarray(thresh.astype("uint8"))
print(pytesseract.image_to_string(im))