一个简单的识别验证码,只能识别简单的

1:pip3 install pytesseract

2:安装tesseract-ocr-setup-4.00.00dev 地址:http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe

3:环境变量:name:TESSDATA_PREFIX  value:C:\Program Files (x86)\Tesseract-OCR\tessdata

  C:\Program Files (x86)\Tesseract-OCR

4.测试代码

import pytesseract
from PIL import Image
from PIL import ImageEnhance
def getyangzhengma(filename):
    image = Image.open(filename)
    imgry = image.convert('L')
    sharpness =ImageEnhance.Contrast(imgry)
    sharp_img = sharpness.enhance(1.0)
    sharp_img.save("image_code.jpg")
    im = Image.open('image_code.jpg')
    vcode = pytesseract.image_to_string(im)
    return vcode

 

posted @ 2017-09-19 19:49  JasonEnbo  阅读(196)  评论(0编辑  收藏  举报