【问题标题】:Improving the tesseract detection改进 tesseract 检测
【发布时间】:2020-06-12 16:41:20
【问题描述】:

我尝试使用 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)

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

【问题讨论】:

    标签: python python-3.x opencv python-tesseract


    【解决方案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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 2021-08-08
      • 2015-02-19
      • 1970-01-01
      • 2015-01-21
      • 2014-01-21
      • 2021-12-28
      相关资源
      最近更新 更多