【问题标题】:Pytesseract detecting scrambled wordsPytesseract 检测乱码
【发布时间】:2021-07-12 23:50:50
【问题描述】:

我有一个简单的 pytesseract 脚本,它在 discord bot 中运行以检测图像中的文本。但是,当给定this image 时,它会返回['ESC es Sum Ls a ns ay', 'on', '', 'Sa eon', '', 'Lape een ne eeren eee eserees', '', 'omeereer ee ate erence ecco at arte', '', 'Ue te eect eet rac contac', '', ' ', '', 'ree Cee ed', 'ema eect eens', '\x0c'] 我的代码是

im = cv2.imread(attachment.filename)
            config = ('-l eng --oem 1 --psm 3')
            text = pytesseract.image_to_string(im, config=config)
            text = text.split('\n')

【问题讨论】:

  • 尝试反转,使文本在白色背景上显示为黑色。还要去看看 tesseract 提高识别率,因为您可能需要使图像中的字符更大。

标签: python discord.py cv2 image-recognition python-tesseract


【解决方案1】:

感谢巴尼的回答,但我所做的是

            image = Image.open(attachment.filename)
            if image.mode == 'RGBA':
                r, g, b, a = image.split()
                rgb_image = Image.merge('RGB', (r, g, b))

                inverted_image = PIL.ImageOps.invert(rgb_image)

                r2, g2, b2 = inverted_image.split()

                final_transparent_image = Image.merge('RGBA', (r2, g2, b2, a))

                final_transparent_image.save(attachment.filename)

            else:
                inverted_image = PIL.ImageOps.invert(image)
                inverted_image.save(attachment.filename)
            im = cv2.imread(attachment.filename)
            text = pytesseract.image_to_string(im)

这基本上反转了颜色/颜色并将其更改为 RGBA。我从中得到了完美的读数!

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 2021-03-31
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 2021-03-12
    相关资源
    最近更新 更多