簡體   English   中英

Pytesseract 檢測亂碼

[英]Pytesseract detecting scrambled words

我有一個簡單的 pytesseract 腳本,它在 discord 機器人中運行,以檢測圖像中的文本。 然而,當給出這個圖像時,它返回['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')

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

            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。 我從中得到了完美的讀數!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM