【问题标题】:Different texts from almost identical images with Tesseract使用 Tesseract 来自几乎相同图像的不同文本
【发布时间】:2020-05-25 19:03:29
【问题描述】:

我有两张几乎一模一样的图片:

其他.png

title.png

我使用 Python 脚本通过 Tesseract 提取文本:

import pytesseract
import cv2

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

def process(path):
    image = cv2.imread(path)
    image = cv2.bitwise_not(image)
    # cv2.imshow('image', image)
    # cv2.waitKey(0)
    results = pytesseract.image_to_string(image, lang='eng', config='')
    print(path, results)

process('title.png')
process('other.png')

这是输出:

title.png ‘CP TOOL
other.png cP TOOL

我没有得到相同的结果。为什么?如何改进文本识别?

图像非常小,但我无法控制生成图像的系统。在处理图像之前,我尝试增加图像的大小:

    factor = 4
    width = int(image.shape[1] * factor)
    height = int(image.shape[0] * factor)
    dim = (width, height)
    image = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)

这两个图像中的文本已正确提取,但我还有其他图像(此处未包含)仍然遇到类似问题(CP 被识别为 cP 特别是)。

我试图在没有有趣效果的情况下腐蚀/扩大图像,但我对 OCR 很陌生,所以我可能做的不正确......

谢谢!

【问题讨论】:

    标签: python ocr tesseract


    【解决方案1】:

    OCR 系统并不完美,但您可以根据您的用例做一些事情来改善结果:

    • 您尝试在使用 tesseract 之前提高输入图像质量
    • 您可以在image_to_string 函数中更改配置
    • 您可以为新字体重新训练 tesseract
    • 您可以尝试其他 OCR 系统
    • 您可以训练您的自定义计算机视觉模型

    我建议查看 tesseract 文档 https://github.com/tesseract-ocr/tessdoc 以获取有关提高质量、配置选项和重新训练 tesseract 的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-31
      • 2014-01-20
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 2013-08-15
      • 1970-01-01
      相关资源
      最近更新 更多