C#. NET Verification Code Intelligent Recognition Learning Note---05c#. NET picture preprocessing
Technical QQ Exchange Group: javadream:251572072
Tutorials Download, online exchange: it.yunsit.cn
Picture after the following preprocessing can be changed a lot clearer, in addition to do image recognition when the general use of TIF format pictures
Below is the picture preprocessing code has the detailed explanation, if does not understand the message to
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 picture preprocessing
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
1. Get all the pictures under the folder return an array
string [] files= Directory.GetFiles (@ "G:\NET Learning \workspace\ Authentication Code identification system used resources \ Sample Pictures", "*.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\ Authentication Code identification system uses resources \newimage\" +i+ ". tif", Imageformat.tiff);
}
}
}
}
private static Bitmap Process (Bitmap Bitmap)
{
1. Create a new picture
Bitmap Newbitmap = new Bitmap (Bitmap. Width, Bitmap. Height);
2. Traverse the entire picture
for (int x = 0; x < bitmap. width;x++)
{
for (int y = 0; y < bitmap. Height; y++) {
3. Remove the border operation
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 point is the background interference color is set 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 it will be set to the original color
Newbitmap.setpixel (x, y, color);
}
}
}
}
return newbitmap;
}
}
}
--------------------------------------------------------------------------------
C#. NET Verification Code Intelligent Recognition Learning Note---05c#. NET picture preprocessing