python code verification process (1)

table of Contents

  This blog series and after that I will introduce various identification verification code. Graphic codes including common, pole test slide codes, touch codes, Twitter grids codes.


An ordinary CAPTCHA

  Before the blog has been to introduce a simple process CAPTCHA, but it will be different and the actual, which is redundant because the lines and interference patterns in the verification code identification image. Therefore, in this case, we need some processing before you can identify the correct result, the following is a method for processing.

1. gradation processing

  Image objects can convert () method passing parameters L, the image can be converted to grayscale images, the following code:

img = Image.open('1.jpg')
image = img.convert('L')
image.show()

The results are:

2. binarization process

  1 can be passed to the binarization processing, the following code:

img = Image.open('1.jpg')
image = img.convert('1')
image.show()

The results are:

  Can also specify a threshold value binarization, the default threshold is 127, must first be specified, it is converted to grayscale images, and specify the binarization threshold value. code show as below:

image = Image.open('1.jpg')
# 先转化为灰度图片
image = image.convert('L')
threshold = 180 # 设置阈值
my = []
for i in range(256):
    if i < threshold:
        my.append(0)
    else:
        my.append(1)

# 二值化处理
image = image.point(my,'1')
image.show()

  Here the original codes in the line has been removed, the verification code become apparent. The time to re-identification codes, the following results:

Guess you like

Origin www.cnblogs.com/ITXiaoAng/p/11828100.html