zoukankan      html  css  js  c++  java
  • 图形验证码的识别

    OCR 技术:

    (1) 在爬虫过程中,难免会遇到各种各样的验证码,而大多数验证码还是罔形验证码,这时候我们可以直接用 OCR 来识别
    (2) OCR ,即 Optical Character Recognition ,光学字符识别, 是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程
    (3) tesserocr 是 Python 的一个OCR 识别库,但其实是对 tesseract 做的一层 Python API 封装,所以它的核心是 tesseract。因此,在安装 tesserocr 之前,我们需要先安装 tesseract


    Windows 下安装 tessorocr:

    1. 先安装 tessoract,下载地址:https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-3.05.01.exe
    2. 再安装 tessorocr,使用 pip3 安装即可:pip3 install tesserocr pillow


    Linux 下安装 tessorocr:

    yum install -y tesseract
    git clone https://github.com/tesseract-ocr/tessdata.git
    sudo mv tessdata/* /usr/share/tesseract/tessdata
    pip3 install tesserocr pillow


    Python 识别图片验证码:

                

    import tesserocr
    from PIL import Image
    
    image = Image.open('1.png')                 # Opens and identifies the given image file
    result = tesserocr.image_to_text(image)     # Recognize OCR text from an image object
    print(result)


    Python 识别有干扰的图片验证码:

    import tesserocr
    from PIL import Image
    
    image = Image.open('2.png')
    
    image = image.convert('L')
    threshold = 127
    table = []
    for i in range(256):
        if i < threshold:
            table.append(0)
        else:
            table.append(1)
    
    image = image.point(table, '1')
    result = tesserocr.image_to_text(image)
    print(result)

         

  • 相关阅读:
    django-day3 Ajax
    django ORM 一对多, 多对多 查询 以及 结合Tamplate
    work-python 脚本 每日发送数据查询
    day16- django
    day15 Jquery
    day 14 JS 练习
    day14 JS-DOM 对象
    day14 JS-BOM
    day14 JS 对象 Function
    day14 js
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10637536.html
Copyright © 2011-2022 走看看