圖片驗證碼灰度化、二值化處理


import tesserocr
from PIL import Image

image = Image.open('code.jpg')
image = image.convert('L')
threshola = 127
table = []
for i in range(256):
    if i < threshola:
        table.append(0)
    else:
        table.append(1)

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

  

from PIL import  Image
import subprocess

image = Image.open('code.jpg')
image = image.point(lambda x: 0 if x<127 else 255)
image.save('code2.jpg')

subprocess.call(["tesseract", 'code2.jpg', "output"])

with open('output.txt', 'r') as f:
    print(f.read())

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM