Example Analysis of C # Verification code recognition base method

Source: Internet
Author: User
Tags 0xc0

This paper describes the basic method of C # Verification code recognition, which is a very practical technique. Share to everyone for your reference. The specific methods are analyzed as follows:


Background

Recently have a friend in a thing, has done pretty good, and finally want to perfect a little, so it is proposed to give this verification code to K.O. And then K.O. This verification code. To achieve a single image recognition time of less than 200ms,500 samples the correct rate of manual statistics is 95%. Because I have no relevant experience, is stones. In the spirit of sharing experience, share the whole idea of analysis. Caught dead in the presence of the great God before you.

Let's take a look at some of the recognition results as shown:

Does this look familiar to you? Here's a concrete analysis.


Process the first step to the background noise and two value of the

For this piece, several methods have been considered.

Method One: The statistical picture color distribution, the color occupation low judgment is the background noise. Because the background noise and the foreground color is not obvious, try many kinds of framing methods can not be very good to remove background noise, eventually abandoned this method.

Method Two: After a little on the net after the next, recently more popular calculation of gray scale after setting a threshold value for binary. In fact, the so-called grayscale image principle is based on the color sensitivity of the human eye to take the weight, the weight of the computer does not have any meaning. Think about it a little bit and you can see that these two processes can be combined completely. So I'm done in one step. Background noise and two value. The threshold value is set to the sum of three components of RGB to 500. The results are very satisfying.


Process the second step to make a character sample

The sample is very important to the computer, because the computer is difficult to have the logical thinking, even if has the logical thinking also must undergo the long-term training to let you satisfy. So make a comparison with a prepared sample. If you look closely at these codes, you will find a bug, and almost all of the code is using the same font, so you can manually create a sample of the font. Since the previous step already has the result of removing the background noise, it can be used directly. Sample making this step is a bit simple and boring, but also need to be careful. Perhaps because one of your careless will result in the recognition rate of a symbol is low. Of these 500 samples, only 31 characters were found. Fortunately, someone in a department also takes the wrong characters into account, such as 1 and i,0 and O. Otherwise, this department will bear more notoriety.


Handle third-step matching

A single match uses the simplest and most primitive two-value comparisons, but matches the matching rate rather than the number of matches. I have defined the relevant scoring principles. The big principle is "should have the addition points, the other has not reduced the points, should not have the moderate reduction, can reach outside the region is not counted."

Because some of the symbols ' partial area match results are similar to those of other symbols, a single match needs to be preferred in an enlarged region. In a certain range, find a best match, the best match is the current position corresponding to the symbol.

Once the best match is made, you can take a big step to the right and push a small step to the right if you can't find the right best match.


Process the fourth step optimization and adjustment

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


Process the fifth step verification results

This step, pure human verification results, statistics out the correct rate.


Thinking:

The result is out, the code is not much, the effect is also very ideal. In this line, most of the time they want to be universal. Whether it is universal or not is largely the level of abstraction. This method is only a simple match, natural can not be universal, but the methods and ideas are universal. Concrete case specific analysis. As for distorted text, hollow text and so on, processing is more complex. There are some ways to use third-party image libraries on the web, and perhaps those methods will be more generic. If you're free, you'll be interested to continue with this theme.


Example Source:

As for this source code should not publish, tangled for a period of time. There is already a similar business activity on the Internet, and this recognition itself is not too difficult, coupled with a system of natural bugs, this code itself is equivalent to no settings, so publish this tag, only for learning communication.

Using system.collections.generic;using system.drawing;using system.io;using system.io.compression;namespace Crack12306captcha{public class cracker{list<charinfo> Words_ = new list<charinfo> ();p ublic Cracker () {var bytes = new byte[] {0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xc5, 0x58, 0xd9, 0x92, 0x13, 0x31,0x0c, 0 X94, 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, 0 x3b, 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, 0x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C, 0xf3, 0xEA, 0x14, 0x80, 0xc1, 0xce, 0x24, 0xEE, 0x72, 0xed, 0x94, 0xaf, 0xfb,0xa9, 0xa A, 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, 0x0 1, 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, 0 Xdb, 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 Memory Stream (bytes)) using (var gzip = new GZipStream (stream, compressionmode.decompress)) using (var reader = new BinaryReader (g Zip) {while (true) {char ch = reader. ReadChar (); if (ch = = ') break;int width = reader. ReadByte (); int height = reader. ReadByte (); bool[,] map = new bool[width, height];for (int i = 0; i < width; i++) for (int j = 0; j < height; j + +) map[ I, j] = reader. Readboolean (); Words_. ADD (New Charinfo (CH, map));}}} public string Read (Bitmap bmp) {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, NE XT); if (matched. Rate > 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 < height; j + +) if (Table[start, j]) return Start;r Eturn start;} Private double Fixedmatch (bool[,] source, bool[,] target, int x0, int y0) {Double total = 0;double count = 0;int Targetwidt H = 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++;elsecount--;} 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);d ouble max = 0;var matched = new Matchedchar (), for (int i = 2, i < 6; i++) for (int j =-3; J < Sourceh Eight-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 = Sc Opematch (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;}}}}

Here's how to use it:

var cracker = new Cracker (); var result = cracker. Read (IMG);

I hope this article is helpful to everyone's C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
Example Analysis of C # Verification code recognition base method

This address: http://www.paobuke.com/develop/c-develop/pbk23463.html






Related content very useful C # string manipulation class stringhelper.csc# implementation simple access to the Code gun information C # simple way to traverse all files in a specified folder the difference between filters, listeners, interceptors in Java
C # get keyword near a text algorithm instance C # implement a bitmap conversion to an icon C # overloaded Equality (= =) Operator Example conversion method for C # files and byte streams

Example Analysis of C # Verification code recognition base method

Contact Us

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.