📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.IO;
using System.Threading;
namespace Unicode_OCR
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox6;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.Label label20;
private System.Windows.Forms.Label label21;
private System.Windows.Forms.Label label22;
private System.Windows.Forms.Label label23;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.ComboBox comboBox3;
private System.Windows.Forms.Label label26;
private System.Windows.Forms.Label label27;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.Label label19;
private System.Windows.Forms.Label label24;
private System.Windows.Forms.Label label28;
private System.Windows.Forms.Label label29;
private System.Windows.Forms.Label label30;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.ComponentModel.IContainer components=null;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
public
//LAST WORKING VALUES
const int number_of_layers=3; //3
const int number_of_input_nodes=150; //150
const int number_of_output_nodes=16; //16
const int maximum_layers=250; //250
const int maximum_number_of_sets=100; //100
int number_of_input_sets;
int epochs =300; //300 & 600(For Latin Arial)
const float error_threshold=0.0002F; //0.0002F
float learning_rate=150F; //150F
float slope=0.014F; //0.014F
int weight_bias=30; //30
int[] layers=new int [number_of_layers];
float[] current_input=new float [number_of_input_nodes];
float[,] input_set=new float [number_of_input_nodes,maximum_number_of_sets];
int[] desired_output=new int [number_of_output_nodes];
int[,] desired_output_set=new int [number_of_output_nodes,maximum_number_of_sets];
float[,] node_output=new float [number_of_layers,maximum_layers];
float[,,] weight=new float [number_of_layers,maximum_layers,maximum_layers];
float[,] error=new float [number_of_layers,maximum_layers];
int[] output_bit=new int [number_of_output_nodes];
int[] desired_output_bit = new int [number_of_output_nodes];
const int rec_width = 5;
const int rec_height = 5;
const int x_org=498;
const int y_org=120;
const int matrix_width=20;
const int matrix_height=30;
int image_start_pixel_x=0;
int image_start_pixel_y=0;
int[] line_top=new int [20];
int[] line_bottom=new int [20];
int current_line=0;
int number_of_lines=0;
bool line_present=true;
bool character_valid=true;
bool character_present=true;
bool trainer_thread_created=false;
string image_file_name;
string image_file_path;
string character_trainer_set_file_name;
string character_trainer_set_file_path;
string network_file_name;
string trainer_string;
string output_string;
System.IO.StreamReader image_file_stream;
System.IO.StreamReader character_trainer_set_file_stream;
System.IO.StreamWriter network_save_file_stream;
System.IO.StreamReader network_load_file_stream;
Random rnd = new Random();
Thread trainer_thread;
UnicodeEncoding unicode = new UnicodeEncoding();
Color[,] ann_input_pixel = new Color[20,30];
Color[,] character_image_pixel = new Color[600,800];
int[,] ann_input_value=new int [20,30];
int[] sample_pixel_x=new int [20];
int[] sample_pixel_y=new int [30];
int input_image_height;
int input_image_width;
int top,bottom,left,right;
int prev_right=20;
int character_height;
int character_width;
Bitmap input_image;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label31;
Bitmap character_image;
public Form1()
{
InitializeComponent();
// TODO: Add any constructor code after InitializeComponent call
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.button3 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label8 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.label31 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.button7 = new System.Windows.Forms.Button();
this.label27 = new System.Windows.Forms.Label();
this.label26 = new System.Windows.Forms.Label();
this.label22 = new System.Windows.Forms.Label();
this.label23 = new System.Windows.Forms.Label();
this.label21 = new System.Windows.Forms.Label();
this.label20 = new System.Windows.Forms.Label();
this.label17 = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.button4 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.label30 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button13 = new System.Windows.Forms.Button();
this.textBox8 = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label25 = new System.Windows.Forms.Label();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.groupBox6 = new System.Windows.Forms.GroupBox();
this.label29 = new System.Windows.Forms.Label();
this.label28 = new System.Windows.Forms.Label();
this.label24 = new System.Windows.Forms.Label();
this.label19 = new System.Windows.Forms.Label();
this.label18 = new System.Windows.Forms.Label();
this.button14 = new System.Windows.Forms.Button();
this.button15 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.groupBox5.SuspendLayout();
this.groupBox6.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(16, 120);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(336, 150);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 40);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(32, 20);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(8, 16);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(32, 20);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "";
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 272);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 24);
this.button2.TabIndex = 5;
this.button2.Text = "Load Image";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// pictureBox2
//
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Location = new System.Drawing.Point(360, 120);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(100, 150);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 6;
this.pictureBox2.TabStop = false;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(96, 40);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(32, 20);
this.textBox3.TabIndex = 7;
this.textBox3.Text = "";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(96, 16);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(32, 20);
this.textBox4.TabIndex = 8;
this.textBox4.Text = "";
//
// openFileDialog1
//
this.openFileDialog1.AddExtension = false;
this.openFileDialog1.DefaultExt = ((string)(configurationAppSettings.GetValue("openFileDialog1.DefaultExt", typeof(string))));
//
// button3
//
this.button3.Location = new System.Drawing.Point(104, 272);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(88, 24);
this.button3.TabIndex = 9;
this.button3.Text = "Next Character";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(24, 16);
this.label1.TabIndex = 10;
this.label1.Text = "Top";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(24, 16);
this.label2.TabIndex = 11;
this.label2.Text = "Left";
//
// label3
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -