C #. NET Verification Code Intelligent Recognition learning notes --- 05C #. Net image preprocessing

Source: Internet
Author: User

C #. NET Verification Code Intelligent Recognition learning notes --- 05C #. Net image preprocessing

C #. NET Verification Code Intelligent Recognition learning notes --- 05C #. Net image preprocessing
Technology qq exchange group: JavaDream: 251572072
Download the tutorial and communicate online: it.yunsit.cn

After preprocessing, the image can be much clearer. In addition, image in tif format is generally used for image recognition.

The following is a detailed description of the image preprocessing code.


Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing. Imaging;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. IO;


Namespace image preprocessing
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}


Private void button#click (object sender, EventArgs e)
{
// 1. Get all the images in the folder and return an array
String [] files = Directory. GetFiles (@ "G: \ NET learning \ workspace \ verification code recognition system resources \ sample images", "*. gif ");
For (int I = 0; I <files. Length; I ++ ){
String file = files [I];
Using (Bitmap bitmap = (Bitmap) Image. FromFile (file )){
Using (Bitmap newBitmap = Process (bitmap )){
NewBitmap. Save (@ "G: \ NET learning \ workspace \ verification code recognition system resources \ newimage \" + I + ". tif", ImageFormat. Tiff );

}
}

}
}


Private static Bitmap Process (Bitmap bitmap)
{
// 1. Create a new image
Bitmap newBitmap = new Bitmap (bitmap. Width, bitmap. Height );
// 2. traverse the entire image
For (int x = 0; x <bitmap. Width; x ++)
{
For (int y = 0; y <bitmap. Height; y ++ ){
// 3. Remove the border
If (x = 0 | y = 0 | x = bitmap. Width-1 | y = bitmap. Height-1)
{
NewBitmap. SetPixel (x, y, Color. White );
}
Else {

Color color = bitmap. GetPixel (x, y );
// 4. If the color of the vertex is background interference, set it to white.
If (color. Equals (Color. FromArgb (204,204, 51) |
Color. Equals (Color. FromArgb (153,204, 51) |
Color. Equals (Color. FromArgb (204,204,204) |
Color. Equals (Color. FromArgb (204,255, 51) |
Color. Equals (Color. FromArgb (204,255,102 )))
{
NewBitmap. SetPixel (x, y, Color. White );
}
Else {
// 5. Otherwise, set it to the original color.
NewBitmap. SetPixel (x, y, color );
}
}
}
}
Return newBitmap;
}
}
}
--------------------------------------------------------------------------------

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.