The following OCR verification code is implemented using. NET, mainly using the Tesseract component.

Source: Internet
Author: User

The OCR verification code below is implemented using. NET, mainly using the Tesseract component.
. NET version Tesseract:
Http://www.pixel-technology.com/freeware/tessnet2/
In addition, this usage is very simple. Note that you need to download the Language Pack. Here I recognize pure letters, so I use the English Language Pack. In addition, in order to improve the verification rate, you can also perform training on your own. Because my requirements are relatively simple, I did not perform this step and used the English Language Pack directly.
Key test code:
 
Ocr = new tessnet2.Tesseract ();
Ocr. SetVariable ("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ");
Ocr. Init (Application. StartupPath @ "\ lng \ eng", "eng", false );
WebClient wc = new WebClient ();
Byte [] oimg = wc. DownloadData ("some url"); // here, the address is hidden. Change it to the address to be recognized.
Bitmap bp = new Bitmap (new MemoryStream (oimg), true );
PictureBox1.Image = bp;
Bp = ImageProcess. RemoveGreen (bp );
Bp = ImageProcess. ToBW (bp );
PictureBox2.Image = bp;
List <tessnet2.Word> result = ocr. DoOCR (bp, Rectangle. Empty );
String txt = "";
Foreach (tessnet2.Word word in result)
{
Txt = word. Text;
}
 
TextBox1.Text = txt; a simple preprocessing is performed on the image to remove interference and convert it into a binary image. For simple verification codes, the effect is good

Related Article

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.