Statement: HereArticleI just recorded my thoughts on the process of processing the 163 album Verification Code image recognition. This post is only for technical purposes. Therefore, no source code download is provided in this article !! I am not responsible for any liability arising from any use of the methods described here !! If you need to reprint this article, please indicate the original author and source !!
I. Recognize the verification code Image
The following is an example of the verification code for several 163 albums:
From the above example, we can know that the verification code of the 163 album only uses the 0-9 digit Verification Code and some interference measures that are commonly seen in the middle of the rule. The 0-9 digit figure is as follows:
Ii. Remove interference
From the above example, we can see that the verification code image of 163 album uses "color changing", "interference point", "interference line ", "displacement" and other "means for automatic interference identification ". therefore, for convenienceProgramFor recognition, interference must be removed first.
"Color Changing": In some simple verification code pictures, the color values of the background color, interference color, and foreground color (Verification code color) are fixed and filled with the color table in different ranges. for images that use this "color-changing method", you can use "binary differentiation" to process the verified image in only two colors before processing. the color of interference points and interference lines and numbers in the 163 Verification Code image are basically random. therefore, the "binary differentiation" solution cannot be used here. (Note: Fortunately, the color of each interference point/line is basically different from that of each verification code, so it provides greater convenience for interference removal.).
"Interference point": It is too easy to deal with those independent interference points. you only need to scan the image once to determine which color points are left blank (the color value is the background color). Then, you can basically determine which points are interference points. then remove (set as the background color.
The following figure shows the verification code after the interference point is removed:
"Interference line": From the comparison between the above two groups, we can see that the effect is not very obvious after the interference points are removed: (the interference line proportion is too large. Therefore, we need to further remove the interference line.Linear typeTo determine whether the color value of a point appears continuously. If the number of consecutive occurrences exceeds 10 times (Hey, leave a job. How does this value come from?), It can basically be determined as a interfering line. But unfortunately, what is used in the. 163 Verification Code image isNon-linear interference line. Therefore, this method does not work. I had to use the "Block signature method" (hey, name of my own ). that is, scan the image again. when scanning to a certain point, take this point as the upper left corner, take the width of 8 to 10 blocks (Another job. How are these two values? If the above job will be done, this should not be a problem.). Then determine the number of times the color value of this point appears in this block. if the number of occurrences exceeds a certain number (this value is very important, because it is related to the "Cleanliness" of the interference line clearing and whether the verification code image will be "mistakenly killed. I used 17 During the test.) The color value is considered to be the color used by the Verification code. otherwise, the scan will continue. until all vertices of the image are scanned. after scanning, it can be considered that, except the color of the scanned verification code, the other colors can be regarded as interference colors and can be directly removed.
The image sample of the Verification Code after processing according to the above method is as follows:
The result is displayed. some images obviously remove the interference line. however, some special (bending special) Interference lines cannot be removed. after the analysis, my ideas are stuck. how can we remove the curved interference wires? After reading the verification code sample image and the 0-9 digital image, a "aha" flash was shown in my mind: why do I need to take blocks for determination (complicate the problem-_-) and directly use the color "step size" (also my own name> P <) isn't statistics enough?
Color step statistics:
In the verification code image, the color of the interference line and Verification Code are different (Worship "color changing"!) And the length and width of the 0-9 digital image are fixed (Here is the assignment answer.). Therefore, the number of occurrences of each color and the coordinates between the first and last appearances are recorded during image scanning. after scanning the image, Count "more than a certain number of occurrences (this number is very important, and I took 20 for the test) the difference between the last and first occurrence of the x-axis must be between positive and negative 8, and the y-axis difference must be between positive and negative 10 (Verification code color ). if the color does not meet this statistical condition, it can be considered as interference color directly removed.
The image sample of the Verification Code after processing according to the above method is as follows:
At this point, all interference lines are perfectly removed. The rest is how to identify the verification code.