1. Introduction to Tesseract:
Tesseract's OCR engine was first developed by the HP lab in 1985 and has become one of the three most accurate recognition engines in the OCR industry by 1995. However, HP soon decided to abandon the OCR business, And Tesseract was also dusty. Several years later, HP realized that it was better to contribute to the open-source software industry than to put tesseract on the shelve. In 2005, Tesseract was acquired by the Information Technology Institute of Nevada, it is expected that Google will improve tesseract, eliminate bugs, and optimize tesseract.
2. Download tesseract:
Http://code.google.com/p/tesseract-ocr/downloads/list, where you can download some files that are essential for identification.
3. Write the Code:
Tesseract can be run in the command line, but it is not easy to use. Therefore, the Code calls the doscommand to implement image recognition.
Using system. diagnostics; process P = new process (); p. startinfo. filename = "cmd.exe"; p. startinfo. useshellexecute = false; p. startinfo. redirectstandardinput = true; p. startinfo. redirectstandardoutput = true; p. startinfo. redirectstandarderror = true; p. startinfo. createnowindow = true; p. start (); string cmd = "tesseract.exe" + picpath + "" + filename + "-l chi_sim"; // The main code is at work. standardinput. writeline (CMD); p. close ();
After image recognition, the recognized content will be saved in a TXT file. We can read the content stored in the TXT file through code and display it intuitively.
Read TXT files
public static string LoadDataFromTXT(string filePath) { string[] line = System.IO.File.ReadAllLines(filePath); return line[0]; }
In this way, you can see this effect.
After many experiments, we found that the recognition accuracy of this simple digital verification code is still very high, but is it so outstanding for the Chinese characters that are profound and profound in the Chinese nation? Let's do the experiment ..
Take a picture with Chinese characters on the Internet:
Let's take a look at the recognition effect of Chinese characters:
I'm disappointed to hear that the Chinese characters are not so powerful, the results are messy, and they are useless at all. We need to make great improvements... However, it provides convenience for us to identify common verification codes ..
This is basically the end of the lecture. By the way, we will explain how to implement the form fade-in and fade-out effect.
Using system. runtime. interopservices; public class Win32 {public const int32 aw_hor_positive = 0x00000001; // open the window from left to right public const int32 aw_hor_negative = 0x00000002; // open the window from right to left: Public const int32 aw_ver_positive = 0x00000004; // open the window from top to bottom: Public const int32 aw_ver_negative = 0x00000008; // open the window from bottom to top: Public const int32 aw_center = 0x00000010; Public const int32 aw_hide = 0x00010000; // Add this constant public const int32 aw_activate = 0x00020000 if you want to use this function during form uninstallation. // After the form is opened through this function, by default, the focus is lost unless the constant public const int32 aw_slide = 0x00040000 is added; Public const int32 aw_blend = 0x00080000; // fade-in and fade-out effect [dllimport ("user32.dll", charset = charset. auto)] public static extern bool animatewindow (intptr hwnd, // handle to window int dwtime, // duration of animation int dwflags // animation type);} win32.animatewindow (this. handle, 1000, win32.aw _ blend); // fade in win32.animatewindow (this. handle, 1000, win32.aw _ slide | win32.aw _ hide | win32.aw _ blend); // fade out
The effect is as follows: