C#. NET Verification Code Intelligent Recognition Learning Note---05c#. NET picture preprocessing

Source: Internet
Author: User

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

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.