# C # basic verification code identification methods and source code,

Source: Internet
Author: User
Tags 0xc0 scale image

C # basic verification code identification methods and source code,
Let's talk about the background of this writing.

A friend has been doing something recently and has already done a good job. Finally, I want to be more perfect, so I proposed to give this verification code to K. o. so K. o. the verification code. The recognition time for a single image is less than 200 ms, and the accuracy rate of manual statistics for 500 samples is 95%. Because I have no relevant experience, I cross the river by feeling the stones. In the spirit of experience sharing, share the overall analysis ideas. It's ugly to everyone.

Let's take a look at some of the recognition results.

Are you familiar with it?

Step 1: Remove background noise and binarization

Several methods are taken into account for this part.

Method 1: Calculate the color distribution of images, and the background noise is determined when the color share is low. Because the difference between background noise and foreground color is not obvious, we tried many methods to avoid background noise and finally gave up this method.

Method 2: I checked it online a little later. Recently, it is quite popular to calculate the gray scale and set a threshold value for binarization. In fact, the so-called gray-scale image principle is based on the human eye's sensitivity to color, this weight is meaningless for computers. If you think about it, you can find that the two processes can be fully merged. As a result, I completed background noise removal and binarization step by step. The threshold value is set to the sum of RGB values to 500. The results were extremely satisfactory.

Process step 2 create character Samples

Samples are very important for computers, because it is difficult for computers to have logical thinking. Even if they have logical thinking, they must undergo long-term training to satisfy you. Therefore, we need to compare the samples we have prepared in advance. If you have carefully observed these verification codes, you will find a bug. Almost all the verification codes use the same font, so you can manually create a set of font samples. The background noise can be directly removed from the previous step. The sample creation step is a bit simple and boring and requires careful attention. It may be because you are not careful, which may lead to a low recognition rate of a symbol. Only 31 characters are found in the 500 samples. Fortunately, a person in a department also takes into account error-prone characters, such as 1 and I, 0 and O. Otherwise, this department will carry more cursing.

Process step 3 matching

A single match uses the simplest and most primitive binary comparison, but the matching rate is not the matching number. I have defined related scoring principles. The general principle is that "this is a bonus. If there is no score reduction, you cannot have a moderate score reduction. The score is not counted if the score is out of the region ".

Because the matching results of some symbols in some regions are similar to those of other symbols, You need to select a single match in an extended region. Find an optimal match within a certain range. The optimal match is the symbol corresponding to the current position.

After an optimal match is completed, the matching position can be pushed to the right for a large step. If no suitable match is found, the matching position can be pushed to the right for a small step.

Process step 4 optimization and adjustment

Any algorithm needs to be optimized and adjusted. Now you need to find the best parameter configuration and the best code organization. This step usually takes the most time and effort.

Process step 5 verification results

In this step, the accuracy rate is calculated based on manpower verification results.

Thoughts

As a result, there are not many codes and the results are ideal. This line is often intended for general purposes. Whether it can be universal is largely at the abstract level. This method is only a simple match and cannot be used in general, but its methods and ideas are universal. Analyze specific cases. As for distorted text and hollow text, processing is much more complicated. There are some ways to use third-party image libraries on the internet, maybe those methods will be more common. If you are interested, continue with this topic.

Source code

As for whether the source code should be released or not, it has been difficult for a while. Similar Business activities already exist on the Internet, and the recognition itself is not too difficult. In addition to the inherent bug of a system, this verification code itself is equivalent to no setup. Therefore, this code is released, only for learning and communication.

Using System. Collections. Generic;
Using System. Drawing;
Using System. IO;
Using System. IO. Compression;
{
Public class Cracker
{
List <CharInfo> words _ = new List <CharInfo> ();
Public Cracker ()
{
Var bytes = new byte [] {
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xc5, 0x58, 0xd9, 0x92, 0x13, 0x31,
0x0c, 0x94, 0x9e, 0x93, 0x0c, 0x61, 0x97, 0x2f, 0xe1, 0x58, 0xe0, 0x91, 0x9b, 0x82, 0x62, 0x0b,
0x58, 0xee, 0xff, 0xff, 0x10, 0xd8, 0xcc, 0xc8, 0xea, 0x96, 0x6c, 0x8f, 0x13, 0x48, 0xe1, 0xaa,
0x4d, 0x46, 0x96, 0x6d, 0xb5, 0x8e, 0x96, 0x67, 0x73, 0x7f, 0x3b, 0x09, 0x0e, 0x25, 0x41, 0x49,
0xa3, 0xae, 0xd7, 0x5b, 0xa9, 0xa8, 0xd5, 0xb4, 0x76, 0x02, 0x6a, 0x5c, 0x52, 0x94, 0x54, 0xed,
0x18, 0x5a, 0x7f, 0x18, 0x00, 0x00, 0x84, 0x07, 0x1b, 0x80, 0x4a, 0x9a, 0x08, 0x35, 0xb8, 0x81,
0x50, 0xe7, 0xad, 0xbe, 0xc4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0xf3, 0xea, 0x14, 0x80, 0xc1, 0xce, 0x24, 0xee, 0x72, 0xed, 0x94, 0xaf, 0xfb,
0xa9, 0xaa, 0x4a, 0xe0, 0xd4, 0x22, 0xc6, 0xf0, 0x57, 0x1d, 0x8e, 0xd2, 0x90, 0xc6, 0x0c, 0xd3,
0x9a, 0x53, 0xfb, 0xd6, 0xb7, 0xdd, 0x14, 0xd4, 0xbd, 0x41, 0xa7, 0x80, 0x7b, 0x23, 0xfe, 0x34,
0x56, 0x0d, 0x96, 0x46, 0x02, 0xfe, 0xfd, 0xb2, 0x00, 0x5f, 0x01, 0x9c, 0xa0, 0x32, 0x39, 0xd7,
0x90, 0xc2, 0x6c, 0xc7, 0x4e, 0x68, 0x88, 0x7d, 0x9f, 0x9b, 0xcf, 0xa7, 0xbe, 0xa0, 0xfc, 0x18,
0x7d, 0x07, 0x5b, 0xa9, 0xbe, 0x56, 0x1f, 0x67, 0x1a, 0x4a, 0x91, 0x9c, 0x04, 0x38, 0x53, 0x6b,
0x70, 0x68, 0x8f, 0xea, 0xf4, 0x34, 0x87, 0x7f, 0x6e, 0x82, 0xc3, 0xc1, 0xab, 0x40, 0xc4, 0x50,
0x13, 0x0e, 0x33, 0x5d, 0x67, 0x7d, 0x01, 0x1f, 0xdb, 0xc0, 0x7f, 0xed, 0x87, 0x7f, 0xbc, 0x0f,
0x75, 0xe0, 0xa5, 0xba, 0xc0, 0x84, 0x3d, 0x24, 0x04, 0xe0, 0xf1, 0x16, 0x41, 0x3b, 0x74, 0xd2,
0x52, 0xc5, 0xf8, 0x7c, 0x12, 0xfb, 0xe4, 0x37, 0x5b, 0xfb, 0x57, 0x11, 0xa1, 0x18, 0x00, 0x00,
};
Using (var stream = new MemoryStream (bytes ))
Using (var gzip = new GZipStream (stream, CompressionMode. Decompress ))
{
While (true)
{

If (ch = '\ 0 ')
Break;
Bool [,] map = new bool [width, height];
For (int I = 0; I <width; I ++)
For (int j = 0; j Map [I, j] = reader. ReadBoolean ();
Words _. Add (new CharInfo (ch, map ));
}
}
}
{
Var result = string. Empty;
Var width = bmp. Width;
Var height = bmp. Height;
Var table = ToTable (bmp );
Var next = SearchNext (table,-1 );

While (next <width-7)
{
Var matched = Match (table, next );
If (matched. Rate & gt; 0.6)
{
Result + = matched. Char;
Next = matched. X + 10;
}
Else
{
Next + = 1;
}
}
Return result;
}
Private bool [,] ToTable (Bitmap bmp)
{
Var table = new bool [bmp. Width, bmp. Height];
For (int I = 0; I <bmp. Width; I ++)
For (int j = 0; j <bmp. Height; j ++)
{
Var color = bmp. GetPixel (I, j );
Table [I, j] = (color. R + color. G + color. B <500 );
}
Return table;
}
Private int SearchNext (bool [,] table, int start)
{
Var width = table. GetLength (0 );
Var height = table. GetLength (1 );
For (start ++; start <width; start ++)
For (int j = 0; j If (table [start, j])
Return start;
Return start;
}
Private double FixedMatch (bool [,] source, bool [,] target, int x0, int y0)
{
Double total = 0;
Double count = 0;
Int targetWidth = target. GetLength (0 );
Int targetHeight = target. GetLength (1 );
Int sourceWidth = source. GetLength (0 );
Int sourceHeight = source. GetLength (1 );
Int x, y;
For (int I = 0; I <targetWidth; I ++)
{
X = I + x0;
If (x <0 | x> = sourceWidth)
Continue;
For (int j = 0; j <targetHeight; j ++)
{

Y = j + y0;
If (y <0 | y> = sourceHeight)
Continue;
If (target [I, j])
{
Total ++;
If (source [x, y])
Count ++;
Else
Count --;
}
Else if (source [x, y])
Count-= 0.55;
}
}
Return count/total;
}
Private MatchedChar ScopeMatch (bool [,] source, bool [,] target, int start)
{
Int targetWidth = target. GetLength (0 );
Int targetHeight = target. GetLength (1 );
Int sourceWidth = source. GetLength (0 );
Int sourceHeight = source. GetLength (1 );
Double max = 0;
Var matched = new MatchedChar ();
For (int I =-2; I <6; I ++)
For (int j =-3; j <sourceHeight-targetHeight + 5; j ++)
{

Double rate = FixedMatch (source, target, I + start, j );
If (rate> max)
{
Max = rate;
Matched. X = I + start;
Matched. Y = j;
Matched. Rate = rate;
}
}
Return matched;
}

Private MatchedChar Match (bool [,] source, int start)
{
MatchedChar best = null;
Foreach (var info in words _)
{

Var matched = ScopeMatch (source, info. Table, start );
Matched. Char = info. Char;
If (best = null | best. Rate <matched. Rate)
Best = matched;
}
Return best;
}
Private class CharInfo
{
Public char Char {get; private set ;}
Public bool [,] Table {get; private set ;}
Public CharInfo (char ch, bool [,] table)
{
Char = ch;
Table = table;
}
}
Private class MatchedChar
{
Public int X {get; set ;}
Public int Y {get; set ;}
Public char Char {get; set ;}
Public double Rate {get; set ;}
}
}
}

Usage:

Var cracker = new Cracker ();
Var result = cracker. Read (img );
C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with \$8882305 \$ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with \$8882305 \$ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.