In the previous article >, how to recognize the simple verification, here is simply the verification code has a number and letter composition, uniform format, each occurrence position fixed. This article will continue to delve into the identification verification code, the goal of this recognition is that the verification code has characters and numbers, the verification code is rotated (may rotate around), the position is not fixed, there is a character and character adhesion, and the verification code has a stronger interferon. This article explains the method, and is not a panacea solution, and the provision of code can not directly solve your problem, here is just the method, the specific needs of the reader to solve their own, it should be explained that the identification code and the specific programming language independent, here is only using the PHP language implementation, using the method described here, You can implement it in any language.
This article steps through the process of identifying the captcha step by step.
For example, we will follow this diagram to unfold.
A: Get a verification code, the first thing we have to do is, binary. The verification code part with 1, the background part with 0, the recognition method is very simple, we print the verification code is a picture of the RGB, and then analyze its law can, through the RGB code, we can easily distinguish the above image of the R value is greater than, G and B value is less than 80, so according to this Rule we can easily put the above picture two value. Look at the two images identified in the primary article
Just looking, it feels complicated. The verification code of the picture each time the background color is not the same, and not monochrome, each code number of colors are different each time. Seemingly difficult to binary, in fact, we print out its RGB value is easy to find. Regardless of how the digital color changes, the RGB value of the number has a value less than 125, so the following judgment
$rgbarray [' Red '] < 125 | | $rgbarray [' Green ']<125| | $rgbarray [' Blue '] < 125
It's easy to tell where the numbers are and where the backgrounds are.
The reason we can find these laws is that in order to make interferon without affecting the digital display effect, the RGB and digital RGB of interferon must be independent of each other and not interfere with each other. As long as we understand this law, we can easily achieve two value.
We found 120, 80, 125 and other thresholds, may differ from the actual RGB, so, sometimes after the binary, there will be some place 1, for the verification code on the fixed position display number, this interference does not make much sense. However, for images where the captcha location is uncertain, it is likely to cause interference when we cut the characters. Therefore, in the binary after the noise out.
Two: Next we take a second step, the noise. The principle of dryness is very simple, is to remove the effective value of isolation, if the noise is relatively high, the requirements of high efficiency, it also has a lot of work to do. Fortunately here we do not require so advanced, we use the simplest method can be, if a point is 1 to determine the point of the upper and lower left and right down to the bottom right of the lower left 8 of the number is 1, if not 1, it is considered a dry point, directly set to 1.
As shown, we use this method to easily find the red box part of the 1 is the dry point, directly set to 1.
We used a technique when judging, sometimes the noise could be two consecutive 1, so we
[Php:collapse] + expand Sourceview plaincopyprint? $num = 0;
if ($data [$i] [$j] = = 1)
{
On
if (Isset ($data [$i -1][$j]) {
$num = $num + $data [$i -1][$j];
}
Under
if (Isset ($data [$i +1][$j]) {
$num = $num + $data [$i +1][$j];
}
Left
if (Isset ($data [$i] [$j-1])) {
$num = $num + $data [$i] [$j-1];
}
Right
if (Isset ($data [$i] [$j +1])) {
$num = $num + $data [$i] [$j +1];
}
Up left
if (Isset ($data [$i -1][$j-1])) {
$num = $num + $data [$i -1][$j-1];
}
Up right
if (Isset ($data [$i -1][$j +1])) {
$num = $num + $data [$i -1][$j +1];
}
Lower left
if (Isset ($data [$i +1][$j-1])) {
$num = $num + $data [$i +1][$j-1];
}
Down right
if (Isset ($data [$i +1][$j +1])) {
$num = $num + $data [$i +1][$j +1];
}
}
if ($num = = 0) {
$data [$i] [$j] = 0;
}
$num = 0;
if ($data [$i] [$j] = = 1)
{
On
if (Isset ($data [$i -1][$j]) {
$num = $num + $data [$i -1][$j];
}
Under
if (Isset ($data [$i +1][$j]) {
$num = $num + $data [$i +1][$j];
}
Left
if (Isset ($data [$i] [$j-1])) {
$num = $num + $data [$i] [$j-1];
}
Right
if (Isset ($data [$i] [$j +1])) {
$num = $num + $data [$i] [$j +1];
}
Up left
if (Isset ($data [$i -1][$j-1])) {
$num = $num + $data [$i -1][$j-1];
}
Up right
if (Isset ($data [$i -1][$j +1])) {
$num = $num + $data [$i -1][$j +1];
}
Lower left
if (Isset ($data [$i +1][$j-1])) {
$num = $num + $data [$i +1][$j-1];
}
Down right
if (Isset ($data [$i +1][$j +1])) {
$num = $num + $data [$i +1][$j +1];
}
}
if ($num = = 0) {
$data [$i] [$j] = 0;
}
We calculate the sum of the values in the 8 directions of this point, and finally we judge whether they are less than the specific thresholds
Three: After the denoising, we get clean two value of data, the next thing to do is to cut the characters. There are many ways to cut a character, and here I use the simplest one, cutting it vertically to become a character, and then removing more than 0000 in the horizontal direction, as
The first step is to cut the red line part, the second step is to cut the blue lines, so that you can get the independent characters. But as in the case below
Press the above method to put the DW The character is cut into one character, which is the wrong cut, so here we relate to the cutting of the adhesion character.
Four: Adhesion character cutting, making verification code, the regular character of the adhesion is easy to split open, if the character itself is scaled, deformation is difficult to deal with, after analysis, we can find that the above character adhesion is a very simple way, just the adhesion of regular characters, so deal with this situation, We also use very simple processing methods. When the split operation, we can not immediately determine the segment is a character, to be verified, the key factor of validation is whether the width of the cut down is greater than the threshold value, the threshold of the choice is that a character no matter how the rotational deformation is not greater than this threshold, so, If we cut the block larger than this threshold, we can think of this as a sticky character, if the sum of more than two threshold values is considered to be three characters sticking, and so on. Once you know the rules, it's easy to cut the sticky characters. If we find a block of sticky characters, we can divide the block directly into two or more new blocks. Of course, in order to better restore characters, I generally use the split +1, 1 of the word converts sequential blocks part of the appropriate supplement.
Five: After the above four steps, we can extract the more pure character block, the next thing to do is to match the character. There are many ways to set up character codes for rotating characters, and this is not an in-depth study. The simplest way I use this is to build a matching library for all of the characters, so the code I provide adds the study operation, which is designed to manually identify the verification code of the image, and then write the signature library through the study method. The more picture data is written, the higher the exact line of validation is recognized.
OK, after the above steps, we can basically identify most of the current Internet authentication code, here we are all using the simplest method, do not use any OCR knowledge. These methods should be at the pinnacle of non-OCR, and more OCR knowledge is needed to identify more complex verification codes. If there is a chance, I will make an introduction in the high-level article.
Below are some easy-to-identify verification code, hoping to attract the attention of site managers.
Some suggestions for making verification codes
For the identification code of the program, the most rare part is to verify the character of the cutting and the establishment of the signature, and many domestic programmers only do the verification code, always like to add a lot of interferon in the verification code, interference line, the effect does not say, but also do not reach a good effect; so, to make their verification code difficult to identify, Just do the following two points, that's enough.
1: The character adhesion, the best all characters have the adhesion part;
2: Do not use the specification character, the various parts of the verification code use different scales or rotations.
As long as these two points, or the two-point deformation, the identification process is difficult to identify. We look at Yahoo and Google's verification code to know that white-white black bottom, but difficult to identify.
Goole:
Yahoo:
Under source file: Click to download Http://www.BkJia.com/uploadfile/2012/0316/20120316111107739.rar
excerpt from the UGG column
Just looking, it feels complicated. The verification code of the picture each time the background color is not the same, and not monochrome, each code number of colors are different each time. Seemingly difficult to binary, in fact, we print out its RGB value is easy to find. Regardless of how the digital color changes, the RGB value of the number has a value less than 125, so the following judgment
$rgbarray [' Red '] < 125 | | $rgbarray [' Green ']<125| | $rgbarray [' Blue '] < 125
It's easy to tell where the numbers are and where the backgrounds are.
The reason we can find these laws is that in order to make interferon without affecting the digital display effect, the RGB and digital RGB of interferon must be independent of each other and not interfere with each other. As long as we understand this law, we can easily achieve two value.
We found 120, 80, 125 and other thresholds, may differ from the actual RGB, so, sometimes after the binary, there will be some place 1, for the verification code on the fixed position display number, this interference does not make much sense. However, for images where the captcha location is uncertain, it is likely to cause interference when we cut the characters. Therefore, in the binary after the noise out.
Two: Next we take a second step, the noise. The principle of dryness is very simple, is to remove the effective value of isolation, if the noise is relatively high, the requirements of high efficiency, it also has a lot of work to do. Fortunately here we do not require so advanced, we use the simplest method can be, if a point is 1 to determine the point of the upper and lower left and right down to the bottom right of the lower left 8 of the number is 1, if not 1, it is considered a dry point, directly set to 1.
Just looking, it feels complicated. The verification code of the picture each time the background color is not the same, and not monochrome, each code number of colors are different each time. Seemingly difficult to binary, in fact, we print out its RGB value is easy to find. Regardless of how the digital color changes, the RGB value of the number has a value less than 125, so the following judgment
$rgbarray [' Red '] < 125 | | $rgbarray [' Green ']<125| | $rgbarray [' Blue '] < 125
It's easy to tell where the numbers are and where the backgrounds are.
The reason we can find these laws is that in order to make interferon without affecting the digital display effect, the RGB and digital RGB of interferon must be independent of each other and not interfere with each other. As long as we understand this law, we can easily achieve two value.
We found 120, 80, 125 and other thresholds, may differ from the actual RGB, so, sometimes after the binary, there will be some place 1, for the verification code on the fixed position display number, this interference does not make much sense. However, for images where the captcha location is uncertain, it is likely to cause interference when we cut the characters. Therefore, in the binary after the noise out.
Two: Next we take a second step, the noise. The principle of dryness is very simple, is to remove the effective value of isolation, if the noise is relatively high, the requirements of high efficiency, it also has a lot of work to do. Fortunately here we do not require so advanced, we use the simplest method can be, if a point is 1 to determine the point of the upper and lower left and right down to the bottom right of the lower left 8 of the number is 1, if not 1, it is considered a dry point, directly set to 1.
http://www.bkjia.com/PHPjc/478321.html www.bkjia.com true http://www.bkjia.com/PHPjc/478321.html techarticle in the previous article PHP implementation Verification Code identification (beginner) http://www.2cto.com/kf/201203/123439.html, how to identify the simple verification, here is simply the verification code has a number ...