Pytesseract 检测乱码

Pytesseract detecting scrambled words

我有一个简单的 pytesseract 脚本,它在 discord 机器人中运行以检测图像中的文本。然而,当给定 this image 时,它 returns ['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')

感谢 barny 的回答,但我所做的是

            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)

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