Original Verification Code:
Before cutting: After cutting:
Before cutting: After cutting:
Before cutting: After cutting:
Before cutting: After cutting:
Before cutting: After cutting:
Directly on the code:
#-*-coding:utf-8-*- fromPILImportImage,imagefilterImportMatplotlib.pyplot as PltImportNumPy as NPImportPandas as PDImportmatplotlib.cm as Cmimg=image.open ("5.png") im=img.convert ("L")a=Np.array (IM) pd. DataFrame (a.sum (axis=0)). Plot.line ()#draw the cumulative value of pixels per columnPlt.imshow (a,cmap='Gray')#Draw an image
# Core Code, note adjust the line to be cut split_lines = [5,16,35,48,66]vlines= [Plt.axvline (i, color='R') forIinchSplit_lines]#draw a split lineplt.show ()" "################ #核心代码 ##########################" "#set to get the height and width of the image, adjust as neededy_min=1Y_max=23IMS=[]c=1 forX_min,x_maxinchZip (split_lines[:-1],split_lines[1:]): Im.crop ([X_min,y_min,x_max,y_max]). Save (Str (c)+'. JPEG') #the crop () function is to intercept the specified image! #Save the image! C=c+1 forIinchRange (1,5): file_name="{}.jpeg". Format (i) Plt.subplot (8,3, i) im=image.open (file_name). CONVERT ("1") #Im=img.filter (Imagefilter.medianfilter (size=3))plt.imshow (IM)#show the captured image! Plt.show ()
Description
This cutting algorithm is suitable for the letter position in the verification code is fixed in a certain range, there is a better cutting effect
Image cutting algorithm for verification code recognition (i.)