图片验证码灰度化、二值化处理


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