C # Identifies the numbers and letters in the picture

Source: Internet
Author: User

A picture recognition gadget, originally mainly to identify the previous company's software registration code in the numbers and letters (each time a box to copy out paste into the registrar, very troublesome!). ), because the registration code appears in the letters and numbers are basically the few, so the scope of the recognition library is set to a relatively small.

The principles and algorithms are explained in detail in the code, the function has a great limitation, but my idea is to share this idea and the way to realize it.

Source:

/* Development ideas: Image grayscale processing, binary, and then the image of the word binary library accurate comparison * * Get the font: The following code in the Generatelicense (Bitmap singlepic) method obtained, the specific operation: * Out of the picture (key out) a character,    Then processing the two-dimensional binary matrix, such as the following character 1 corresponding to the two-dimensional matrix * 00000 * 00100 * 11100 * 00100 * 00100 * 00100 * 00100 * 00100 * 00100 * 11111 * 00000 * 00000 * * NOTE: "The same characters, such as 1, different fonts, font size, different zoom size of the picture, obtained to the two-bit matrix 0, 1 and the number are different!" * So according to this method to write a match all words, the font is big ... * **////<summary>///extracts the characters within the image (converting the grayscale-processed image into a two-bit array of 0, 1)///</summary>///<param name= "Singlepic" > Picture source </param>public void Generatelicense (Bitmap singlepic) {try {char[,] Chararray = new Char[singlepic. Height, Singlepic.  Width];  A two-dimensional array that defines a chai type records a value of 0/1 on each pixel, forming a rectangle int imagewidth = 0;  The pixel width of the recording picture int imageheight = 0;  Record the pixel height of the picture int dggrayvalue = 128;    Grayscale value Color Piexl;  String code = ""; Stores 0/1 for each pixel for (int posy = 0; posy < Singlepic. Height;  posy++) {//From top to bottom string codecache = ""; 0/1 for (int posx = 0; posx < singlepic) for each row of pixels stored. Width;      posx++) {//From left to right  Piexl = Singlepic.        GetPixel (POSX, posy); if (PIEXL.        R < Dggrayvalue) {//If the color of the pixel is black, the value is "1" Codecache = Codecache + "1";        } else {//otherwise the color of the pixel is white and the value is "0" Codecache = Codecache + "0";  }} char[] array = Codecache.tochararray ();      The value of 0/1 per row is saved with a number so that it can be recycled//code + = Codecache + "\ n"; for (imagewidth = 0; imagewidth < array. Length;  imagewidth++) chararray[imageheight, imagewidth] = Array[imagewidth];    imageheight++ the values of each row into a two-dimensional array through a loop; //********************* The above code can be used to get a picture of a word binary array, that is, the font *****************************//start and font to match (my tool only requires the following characters) FINDW    Ord (Chararray, Char0, ImageHeight, ImageWidth, BinaryWidth0, BinaryHeight0, ' 0 ');    Findword (Chararray, Char1, ImageHeight, ImageWidth, BinaryWidth1, BinaryHeight1, ' 1 ');    Findword (Chararray, Char2, ImageHeight, ImageWidth, BinaryWidth2, BinaryHeight2, ' 2 '); Findword (Chararray, Char3, ImageHeight, ImageWidth, BinaryWidth3, BINARYHEIGHT3, ' 3 ');    Findword (Chararray, CHAR4, ImageHeight, ImageWidth, BinaryWidth4, BinaryHeight4, ' 4 ');    Findword (Chararray, CHAR5, ImageHeight, ImageWidth, BinaryWidth5, BinaryHeight5, ' 5 ');    Findword (Chararray, CHAR6, ImageHeight, ImageWidth, BinaryWidth6, BinaryHeight6, ' 6 ');    Findword (Chararray, CHAR7, ImageHeight, ImageWidth, BinaryWidth7, BinaryHeight7, ' 7 ');    Findword (Chararray, Char8, ImageHeight, ImageWidth, BinaryWidth8, BinaryHeight8, ' 8 ');    Findword (Chararray, Char9, ImageHeight, ImageWidth, BinaryWidth9, BinaryHeight9, ' 9 ');    Findword (Chararray, CharA, ImageHeight, ImageWidth, Binarywidtha, Binaryheighta, ' a ');    Findword (Chararray, Charb, ImageHeight, ImageWidth, BINARYWIDTHB, BINARYHEIGHTB, ' B ');    Findword (Chararray, Charc, ImageHeight, ImageWidth, binarywidthc, BINARYHEIGHTC, ' C ');    Findword (Chararray, Chard, ImageHeight, ImageWidth, BINARYWIDTHD, BINARYHEIGHTD, ' d ');    Findword (Chararray, CharE, ImageHeight, ImageWidth, binarywidthe, Binaryheighte, ' e ');Findword (Chararray, Charf, ImageHeight, ImageWidth, BINARYWIDTHF, BINARYHEIGHTF, ' f ');    Findword (Chararray, Charp, ImageHeight, ImageWidth, BINARYWIDTHP, BINARYHEIGHTP, ' P ');    Findword (Chararray, Chary, ImageHeight, ImageWidth, Binarywidthy, binaryheighty, ' Y '); ------------------------------------END---------------------------------------------Richtextboxlicense.text +  = Identifysort (); Execute the Identifysort method to display the format I want in the richtextboxlicense text box Richtextboxlicense.selectionstart =  Richtextboxlicense.textlength; Move cursor to last face} catch {}}

The above mentioned is the whole content of this article, I hope you can like.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Identifies the numbers and letters in the picture

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






Related content talk about the conversion between C # picture and byte[] and byte[] and string C # Delegation in detail C # a stack instance that reads excelc# data structures using Aspose.cells controls
The basic usage of lock system in C # Multithreading programming C # Implementing the Lunar Calendar Method C # uses WinForm to realize the difference between struct and class in Android-like listenerc#

C # Identifies the numbers and letters in the picture

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.