- 1、 General graphic verification code
In this blog and subsequent series, I will introduce you to the identification of various verification codes. It includes ordinary graphic verification code, polar sliding verification code, touch verification code and Weibo palace verification code.
1、 General graphic verification code
. Therefore, in this case, we need to do some processing before we can identify the correct results. The following is the processing method.
1. Gray processing
You can use the convert() method of the image object to pass in the parameter l to convert the image into a gray-scale image, as shown in the following code:
img = Image.open('1.jpg') image = img.convert('L') image.show()
The result is:
2. Binary treatment
You can pass in 1 for binarization, as follows:
img = Image.open('1.jpg') image = img.convert('1') image.show()
The result is:
You can also specify the threshold value of binarization. The default threshold value is 127. If you want to specify it, you must first convert it to a gray-scale image, and then specify the threshold value of binarization. The code is as follows:
image = Image.open('1.jpg') #Convert to gray image first image = image.convert('L') Threshold = 180 ා set threshold my =  for i in range(256): if i < threshold: my.append(0) else: my.append(1) #Binary treatment image = image.point(my,'1') image.show()
the lines in the original verification code have been removed and the verification code has become very clear. At this time, the verification code is re identified, and the results are as follows: