コード例 #1
0
        private void btnRecognize_Click(object sender, EventArgs e)
        {
            DownSample ds = new DownSample(this.entryImage);

            this.downsampled = ds.PerformDownSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
            this.sample.Invalidate();

            if (this.network == null)
            {
                MessageBox.Show("I need to be trained first!");
                return;
            }

            int sampleSize = OCRForm.DOWNSAMPLE_HEIGHT * OCRForm.DOWNSAMPLE_WIDTH;
            var input      = new BasicMLData(sampleSize);

            for (int i = 0; i < sampleSize; i++)
            {
                input[i] = this.downsampled[i] ? 0.5 : -0.5;
            }

            int best = this.network.Winner(input);

            char[] map = MapNeurons();
            MessageBox.Show("  " + map[best] + "   (Neuron #"
                            + best + " fired)", "That Letter Is");
            ClearEntry();
        }
コード例 #2
0
        private void btnSample_Click(object sender, EventArgs e)
        {
            DownSample ds = new DownSample(this.entryImage);

            this.downsampled = ds.PerformDownSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
            this.sample.Invalidate();
        }
コード例 #3
0
        public void ClearEntry()
        {
            Brush whiteBrush = new SolidBrush(Color.White);

            entryGraphics.FillRectangle(whiteBrush, 0, 0, entry.Width, entry.Height);
            entry.Invalidate();
            DownSample ds = new DownSample(this.entryImage);

            this.downsampled = ds.PerformDownSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
            this.sample.Invalidate();
        }
コード例 #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DownSample ds = new DownSample(this.entryImage);

            this.downsampled = ds.PerformDownSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
            this.sample.Invalidate();
            String Prompt  = "What letter did you just draw.";
            String Title   = "Input Required";
            String Default = "";
            Int32  XPos    = ((SystemInformation.WorkingArea.Width / 2) - 200);
            Int32  YPos    = ((SystemInformation.WorkingArea.Height / 2) - 100);

            bool valid = false;

            for (int i = 0; i < this.downsampled.Length; i++)
            {
                if (this.downsampled[i])
                {
                    valid = true;
                }
            }

            if (!valid)
            {
                MessageBox.Show("Please draw a letter before adding it.");
                return;
            }

            String Result = Microsoft.VisualBasic.Interaction.InputBox(Prompt, Title, Default, XPos, YPos);

            if (Result != null)
            {
                Result = Result.ToUpper();
                if (Result.Length == 0)
                {
                    MessageBox.Show("Please enter a character.");
                }
                else if (Result.Length > 1)
                {
                    MessageBox.Show("Please enter only a single character.");
                }
                else if (this.letterData.ContainsKey(Result[0]))
                {
                    MessageBox.Show("That letter is already defined, please delete first.");
                }
                else
                {
                    this.letters.Items.Add(Result);
                    this.letterData.Add(Result[0], this.downsampled);
                    this.ClearEntry();
                }
            }
        }
コード例 #5
0
ファイル: OCRForm.cs プロジェクト: DoctorBoo/ML
 public void ClearEntry()
 {
     Brush whiteBrush = new SolidBrush(Color.White);
     entryGraphics.FillRectangle(whiteBrush, 0, 0, entry.Width, entry.Height);
     entry.Invalidate();
     DownSample ds = new DownSample(this.entryImage);
     this.downsampled = ds.downSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
     this.sample.Invalidate();
 }
コード例 #6
0
ファイル: OCRForm.cs プロジェクト: DoctorBoo/ML
 private void btnSample_Click(object sender, EventArgs e)
 {
     DownSample ds = new DownSample(this.entryImage);
     this.downsampled = ds.downSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
     this.sample.Invalidate();
 }
コード例 #7
0
ファイル: OCRForm.cs プロジェクト: DoctorBoo/ML
        private void btnRecognize_Click(object sender, EventArgs e)
        {
            DownSample ds = new DownSample(this.entryImage);
            this.downsampled = ds.downSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
            this.sample.Invalidate();

            if (this.network == null)
            {
                MessageBox.Show("I need to be trained first!");
                return;
            }

            int sampleSize = OCRForm.DOWNSAMPLE_HEIGHT * OCRForm.DOWNSAMPLE_WIDTH;
            double[] input = new double[sampleSize];

            for (int i = 0; i < sampleSize; i++)
            {
                input[i] = this.downsampled[i] ? 0.5 : -0.5;
            }

            int best = this.network.Winner(input);
            char[] map = mapNeurons();
            MessageBox.Show("  " + map[best] + "   (Neuron #"
                            + best + " fired)", "That Letter Is");
            ClearEntry();
        }
コード例 #8
0
ファイル: OCRForm.cs プロジェクト: DoctorBoo/ML
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DownSample ds = new DownSample(this.entryImage);
            this.downsampled = ds.downSample(OCRForm.DOWNSAMPLE_WIDTH, OCRForm.DOWNSAMPLE_HEIGHT);
            this.sample.Invalidate();
            String Prompt = "What letter did you just draw.";
            String Title = "Input Required";
            String Default = "";
            Int32 XPos = ((SystemInformation.WorkingArea.Width / 2) - 200);
            Int32 YPos = ((SystemInformation.WorkingArea.Height / 2) - 100);

            bool valid = false;
            for (int i = 0; i < this.downsampled.Length; i++)
            {
                if (this.downsampled[i])
                {
                    valid = true;
                }
            }

            if (!valid)
            {
                MessageBox.Show("Please draw a letter before adding it.");
                return;
            }

            String Result = Microsoft.VisualBasic.Interaction.InputBox(Prompt, Title, Default, XPos, YPos);
            if (Result != null)
            {
                Result = Result.ToUpper();
                if (Result.Length == 0)
                {
                    MessageBox.Show("Please enter a character.");
                }
                else if (Result.Length > 1)
                {
                    MessageBox.Show("Please enter only a single character.");
                }
                else if (this.letterData.ContainsKey(Result[0]))
                {
                    MessageBox.Show("That letter is already defined, please delete first.");
                }
                else
                {
                    this.letters.Items.Add(Result);
                    this.letterData.Add(Result[0], this.downsampled);
                    this.ClearEntry();
                }
            }


        }