Python实现图片验证码识别

转载地址:https://blog.csdn.net/EB_NUM/article/details/77060009

具体想要实现上面的代码需要安装两个包和一个引擎 
在安装之前需要先安装好Python,pip并配置好环境变量


  1.  
    1.第一个包: pytesseract
  2.  
     
  3.  
    pip install pytesseract

若是出现安装错误的情况,安装不了的时候,可以将命令改为 pip.exe install pytesseract来安装 
若是将pip修改为pip.exe安装成功后,那么下文的所有pip都需要改为pip.exe

  1.  
    2.第二个包:PIL安装
  2.  
     
  3.  
    pip install PIL

若是失败了可以如下修改 pip install PILLOW

3.安装识别引擎tesseract-ocr

下载 tesseract-ocr,进行默认安装 下载地址点击这里

 

具体代码可以看这里

 

  1.  
    from PIL import Image
  2.  
    import pytesseract
  3.  
     
  4.  
    imageObject=Image.open('D://new.jpg')
  5.  
    print (imageObject)
  6.  
    print (pytesseract.image_to_string(imageObject))

识别图片 
这里写图片描述

我们发现运行时报错了 
这里写图片描述

解决方法(D:/Python 该路径为Python安装位置,因人而异) 
D:/Python/Lib/site-packages/pytesseract 下的 pytesseract.py文件做如下修改

这里写图片描述


执行成功看下结果: 
这里写图片描述

 

posted @ 2019-04-01 16:33  Halo3224  阅读(2059)  评论(0编辑  收藏  举报
热爱技术的小牛