Python Verification Code recognition processing

Source: Internet
Author: User

Read Catalogue

    • Preparatory work
    • Verify
    • Instance

Most of the system in the user login requires the user to enter a verification code, verification code of a lot of types, there are alphanumeric, there are Chinese characters, and even the user input an arithmetic question answer, for the system to use the verification code can be effective to prevent using machine guessing method of the password spying, to a certain extent increased security

preparatory work

Processing verification code requires PIL library, Pytesser library support

1. Install PIL Library

Download, download is exe application, directly double-click the installation, it will automatically install into the Python lib\site-packages directory

2. Install Pytesser Library

Website Download | Blog Park download, download and unzip directly placed in the Python lib\site-packages directory, while creating a new pytheeer.pth, the content is written pytesser, meaning is to specify the Pytesser folder

3. Download Tesseract OCR engine

Website Download | Blog Park download, download and unzip, the Tesseract directory under the Tessdata cover Pytesser directory Tessdata

Back to the top of the verification

Back to top instance

Principle: Color to grayscale, gray to two value, binary image recognition

#coding: utf-8#-----------------------------------# Program: getverify.py# version: v0.1# vforbox# language: Python 2.7# action: Run directly # Function: Verification code Identification Processing #------------------------------------# Verification Code identification, this program can only identify data verification code import osfrom pytesser Import * #变更工程路径os. ChDir (' D:\Python27\Lib\site-packages\pytesser ') #二值化 (what is the threshold value of 140?). Try it out) threshold = table = [] for I in range (up to): If I < threshold:table.append (0) E        Lse:table.append (1) #由于都是数字 #对于识别成字母的 Use the table for correction rep={' O ': ' 0 ', ' I ': ' 1 ', ' L ': ' 1 ', ' Z ': ' 2 ',    ' S ': ' 8 '}; def getverify (name): #打开图片 im = Image.open (name) #转化到灰度图 (brightness) imgry = Im.convert (' L ') #保存上面转 The image imgry.save (' Gray_ ' +name) #二值化, using the threshold segmentation method, threshold for the split point out = imgry.point (table, ' 1 ') #保存上面分割的二值化 ou T.save (' Binary_ ' +name) #识别转化为文本 text = image_to_string (out) #识别是否正确 text = Text.strip () Text =          Text.upper (); For i in Rep:text = Text.replace(I,rep[i]) print text return text# call function getverify (' 1.jpg ') #这里的图片保证在pytesser目录下 

SOURCE download

Python Verification Code recognition processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.