• python 验证码识别


    一、python识别简单验证码:

      代码: 

     1 '''
     2     func:实现简单验证码获取
     3 '''
     4 import pytesseract
     5 from PIL import Image
     6 
     7 #首先通过Image打开一个图片
     8 image=Image.open('code1.jpg')
     9 # #然后通过方法将image对象转化为字符串
    10 # code=pytesseract.image_to_string(image)
    11 # print(code)
    12 
    13 #出现错误,需要将图片进行灰度转化和二值处理
    14 image=image.convert('L')
    15 # image2=image1.convert('1')
    16 # image1.show()
    17 #这里设定需要处理的阈值
    18 threshold = 130
    19 table = []
    20 for i in range(256):
    21     if i < threshold:
    22         table.append(0)
    23     else:
    24         table.append(1)
    25 image=image.point(table,'1')
    26 image.show()
    27 code=pytesseract.image_to_string(image)
    28 print(code)

    二、处理极验滑动验证码:

      1、步骤:

        ·模拟点击验证按钮。 --可以通过selenium来完成。

        ·识别滑动缺口的位置。--需要用图像处理的方法来完成。

        ·模拟拖动滑块。 --

    '''
    func:实现简单验证码获取
    '''
    import pytesseract
    from PIL import Image

    #首先通过Image打开一个图片
    image=Image.open('code1.jpg')
    # #然后通过方法将image对象转化为字符串
    # code=pytesseract.image_to_string(image)
    # print(code)

    #出现错误,需要将图片进行灰度转化和二值处理
    image=image.convert('L')
    # image2=image1.convert('1')
    # image1.show()
    threshold = 130
    table = []
    for i in range(256):
    if i < threshold:
    table.append(0)
    else:
    table.append(1)
    image=image.point(table,'1')
    image.show()
    code=pytesseract.image_to_string(image)
    print(code)

  • 相关阅读:
    简单马周游问题1152siicly
    Sicily 1155. Can I Post the lette
    POJ 1007
    给定2个大小分别为n, m的整数集合,分别存放在两个数组中 int A[n],B[m],输出两个集合的交集。
    算法1--
    GAN
    为什么ConcurrentHashMap是弱一致的
    手写HASHMAP
    千万级规模高性能、高并发的网络架构经验分享
    Web 通信 之 长连接、长轮询(转)
  • 原文地址:https://www.cnblogs.com/monty12/p/10004051.html
Copyright © 2020-2023  润新知