The technical content of the voting software is identified by the Verification code. To prevent cheating in voting, many voting websites add Random verification codes. You can only vote after entering the verification code. However, if you add a verification code, you can be foolproof. Although not all verification codes can be identified (for example, QQ's deformed Chinese Character verification codes cannot be identified by software, I personally think), there are still many verification codes that can be identified by software.
The following usesThe comment verification code in Tianya blog isExample:
Step 1. Obtain the verification code Image
C # You can use the HTTP webrequest get verification code URL to obtain the returned data stream, and then assign the data stream value to the bitmap variable. Put a picturebox control in winform and specify its image attribute as a bitmap variable to display the verification code image.
You can also use the Save method of Bitmap to save the image as a BMP file.
Stream resstream = response. getresponsestream (); // obtain the verification code data stream
Bitmap sourcebm = new Bitmap (resstream); // initialize the bitmap image to enlarge the verification code image by 1600% in Photoshop
Step 2: remove the verification code image (convert the color to grayscale)
Color removal is used to further form a black/white two-color image.
Color c = sourcebm. getpixel (x, y );
Int Luma = (INT) (C. R * 0.3 + c. g * 0.59 + C. B * 0.11); // grayscale conversion algorithm
Sourcebm. setpixel (X, Y, color. fromargb (Luma, Luma, Luma ));
Step 3: remove the noise and convert it to a black-and-white image
It can be seen from the grayscale image that the color of the number is relatively deep, while the color is relatively light, so you can set a critical color value, the color above or equal to this value is set to white, the value lower than this value is set to black.
Color c = sourcebm. getpixel (x, y );
If (C. R> = critical_value)
Sourcebm. setpixel (X, Y, color. fromargb (255,255,255 ));
Else
Sourcebm. setpixel (X, Y, color. fromargb (0, 0, 0 ));
Step 4: dynamically obtain the boundary of each number
For (INT x = 0; x <sourcebm. width; X ++)
{
Mycolumn = true;
For (INT y = 0; y <sourcebm. height; y ++)
{
Color c = sourcebm. getpixel (x, y );
If (C. R = 0 & charstart = false) // black spots appear for the first time
{
Widthstartx [charnum] = X;
Charstart = true;
Break;
}
If (C. R = 0 & charstart = true) // black spots appear later
{
Mycolumn = false;
Break;
}
}
If (mycolumn = true & charstart = true & widthstartx [charnum] <X) // If the column has no black spots and the front black spots have not ended
{
Widthendx [charnum] = x-1;
Charstart = false;
Charnum ++;
}
If (charstart = true & mycolumn = false & X = (BMP. Width-1) // if the black spot begins to appear, and the last column also has a black spot
{
Widthendx [charnum] = X;
Charstart = false;
Charnum ++;
}
}
5. Obtain the signature for each character
Within the boundary of each character, each pixel is detected. If the pixel is white, the value is "0". If the pixel is black, the value is "1 ", connecting "0" and "1" is the pattern of the number or character.
Color c = sourcebm. getpixel (x, y );
If (C. R = 0)
STR = STR + "1 ";
Else
STR = STR + "0 ";
6. complete verification code Image Recognition
Save the obtained signature and the corresponding number or character. Next time, compare the new signature with the saved one. If the same, extract the corresponding number or character, the verification code is identified.
Automatic voting system tutorial ___ verification code recognition http://blog.csdn.net/jiali765/article/details/6323382
The voting verification code is divided into multiple levelsIs it simple or?
Click to learn more