1. Download remote Images
2. grayscale conversion
3. image splitting
4. Obtain the image segmentation pattern by grayscale
(The verification code signature for the image change is not very accurate)
The color is the image obtained from the original website.
Gray is the converted grayscale image.
The following is the split image.
The following list shows the signature.
Grayscale conversion is the code 1/** // <summary>
2 // grayscale conversion, point-by-point
3 /// </summary>
4 public void GrayByPixels ()
5 {
6 for (int I = 0; I <bmpobj. Height; I ++)
7 {
8 for (int j = 0; j <bmpobj. Width; j ++)
9 {
10 int tmpValue = GetGrayNumColor (bmpobj. GetPixel (j, I ));
11 bmpobj. SetPixel (j, I, Color. FromArgb (tmpValue, tmpValue, tmpValue ));
12}
13}
14}
Image segmentation public Bitmap [] getsplitpicsbyblkcol (int RowNum, int dgGrayValue)
{
If (RowNum = 0)
Return null;
Int singW = bmpobj. Width/RowNum;
Bitmap [] PicArray = new Bitmap [RowNum];
Rectangle cloneRect;
Int MinCol = 0, OldCol = 0;
Int Points, MinPoints;
For (int j = 0; j <RowNum-1; j ++)
{
MinPoints = bmpobj. Height;
For (int k = j * singW; k <(j + 1) * singW + singW/2; k ++) // find the smallest vertex Sequence
{
Points = 0;
For (int I = 0; I <bmpobj. Height; I ++)
{
If (bmpobj. GetPixel (k, I). R <dgGrayValue) // count
Points ++;
}
If (Points <MinPoints)
{
If (k-j * singW> singW/2) // the second half of the character
{
MinPoints = Points;
MinCol = k;
}
}
}
If (MinCol-OldCol + 1 <= singW/2) // less than half of the width
MinCol = (j + 1) * singW;
// Extract small plot
If (MinPoints> 0) // There is an intersection
CloneRect = new Rectangle (OldCol, 0, MinCol-OldCol + 1, bmpobj. Height );
Else
CloneRect = new Rectangle (OldCol, 0, MinCol-OldCol, bmpobj. Height );
OldCol = MinCol;
PicArray [j] = bmpobj. Clone (cloneRect, bmpobj. PixelFormat); // copy a small image
}
CloneRect = new Rectangle (OldCol, 0, bmpobj. Width-OldCol, bmpobj. Height );
PicArray [RowNum-1] = bmpobj. Clone (cloneRect, bmpobj. PixelFormat); // The Last
Return PicArray;
}
Whether the verification code can be obtained accurately or when the grayscale conversion is required, the grayscale value is obtained moderately, and the correct signature can be obtained through accurate segmentation. It is very easy to recognize common image verification codes.