【问题标题】:How to increase likeliness of image recognition with pytesseract如何使用 pytesseract 增加图像识别的可能性
【发布时间】:2017-10-24 02:04:27
【问题描述】:

我正在尝试将此图像列表转换为文本。图像相当小但非常易读(15x160,只有灰色文本和白色背景)我似乎无法让 pytesseract 正确读取图像。我试图用 .resize() 来增加大小,但它似乎根本没有做太多。这是我的一些代码。我可以添加什么新东西来增加我的机会吗?就像我说的,我很惊讶 pytesseract 在这里让我失望了,与我似乎捕捉到的一些东西相比,它很小但超级可读。

for dImg in range(0, len(imgList)):
    url = imgList[dImg]
    local = "img" + str(dImg) + ".jpg"
    urllib.request.urlretrieve(url, local)
    imgOpen = Image.open(local)
    imgOpen.resize((500,500))
    imgToString = pytesseract.image_to_string(imgOpen)
    newEmail.append(imgToString)

【问题讨论】:

    标签: python ocr python-tesseract pytesser


    【解决方案1】:

    设置页面分割模式 (psm) 可能会有所帮助。

    要获取所有可用的 psm,请在终端中输入 tesseract --help-psm

    然后确定与您的需要相对应的 psm。假设您想将图像视为单个文本行,在这种情况下您的 ImgToString 变为:

    imgToString = pytesseract.image_to_string(imgOpen, config = '--psm 7')
    

    希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      您可以在代码中执行多个预处理步骤。

      1) 使用from PIL import Imageyour_img.convert('L')。您可以检查其他几个设置。

      2) 有点高级的方法:使用 CNN。您可以使用几个预训练的 CNN。在这里您可以找到更详细的信息:https://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/sampling/sampling.pdf

      提菲

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-30
        • 1970-01-01
        • 2016-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-19
        相关资源
        最近更新 更多