tesserocr識別圖形驗證碼

前提: 配置好了tesserocr的相關環境,配置可以參看tesserocr環境配置。

CODE:

1、非常簡單的識別,在本地的目錄。

import tesserocr
from PIL import Image

image = Image.open('0.png')
print(tesserocr.image_to_text(image))

2、轉化二值化再操作。

import tesserocr
from PIL import Image

image = Image.open('1.png')
# 將圖片轉化爲灰度圖像
# image = image.convert('L')

# 將圖片進行二值化操作
# image = image.convert('1')

image.show()

3、應對有干擾的驗證,設置閾值操作。

import tesserocr
from PIL import Image

image = Image.open('1.png')
# 將圖片轉化爲灰度圖像
image = image.convert('L')
# 設定默認的閾值
threshold = 125
table = []
for i in range(256):
    if i<threshold:
        table.append(0)
    else:
        table.append(1)

image = image.point(table, '1')
print(tesserocr.image_to_text(image))
image.show()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章