zoukankan      html  css  js  c++  java
  • python验证码识别PIL+pytesseract

    1.需要模块安装

       在python安装目录scripts即:

       执行pip install pillow

      下载tesseract-ocr-setup-4.00.00dev.exe 安装,我的目录在C盘默认

      执行pip install pytesseract

    2.上传测试案例

           

    3.示例代码

     图片处理过程:

     1 from PIL import Image
     2 from pytesseract import *
     3 import PIL.ImageOps
     4 
     5 def initTable(threshold=140):
     6     table = []
     7     for i in range(256):
     8         if i < threshold:
     9             table.append(0)
    10         else:
    11             table.append(1)
    12     return table
    13 
    14 im = Image.open('new.jpg')
    15 #图片的处理过程
    16 im = im.convert('L')
    17 #像素点处理 二值图像,非黑即白 相当于去噪操作
    18 binaryImage = im.point(initTable() , '1')
    19 #binaryImage.show()
    20 #模式“L”为灰色图像,它的每个像素用8个bit表示,0表示黑,255表示白,其他数字表示不同的灰度 
    21 imgl = binaryImage.convert('L')
    22 #输入图像转换为反色图像
    23 imginvert = PIL.ImageOps.invert(imgl)
    24 #imginvert.show()
    25 vercode = pytesseract.image_to_string(imginvert)
    26 print (vercode)

    识别结果:

  • 相关阅读:
    Exception和Error有什么区别?
    网络流量劫持的含义
    安全术语:
    加载相关
    10、接到任务后的整个测试前准备流程总结
    fiddler工具栏数据解释
    HTTP的请求头标签 If-Modified-Since
    VueStudyDemo
    Vue从入门到放弃
    TypeScript初体验
  • 原文地址:https://www.cnblogs.com/linsu/p/8458961.html
Copyright © 2011-2022 走看看