Пример #1
0
        private void button21_Click(object sender, EventArgs e)
        {
            ANNWrapper.LoadBPParameters(Application.StartupPath + "\\" + textParas.Text);

            string fileName = Application.StartupPath + "\\" + textSubsystemBMP.Text;
            Bitmap bmp      = new Bitmap(fileName);
            IntPtr hBmp     = bmp.GetHbitmap();

            bool needRevert = false;

            ANNWrapper.SaveBlockToBMP4(hBmp, int.Parse(textLeft.Text),
                                       int.Parse(textTop.Text),
                                       int.Parse(textRight.Text),
                                       int.Parse(textBottom.Text),
                                       Application.StartupPath + "\\" + textInputBMP.Text,
                                       Int32.Parse(textInputInt.Text),
                                       needRevert);

            string ret = "";

            if (NumberParse_1(Application.StartupPath + "\\" + textInputBMP.Text, out ret))
            {
                MessageBox.Show(ret);
            }
            else
            {
                MessageBox.Show("Numeral Parser Error!");
            }
            DeleteObject(hBmp);
        }
Пример #2
0
        private void button14_Click(object sender, EventArgs e)
        {
            if (textParas.Text.Length > 0)
            {
                ANNWrapper.LoadBPParameters(Application.StartupPath + "\\" + textParas.Text);
            }
            else
            {
                ANNWrapper.InitBPParameters(64, 8, 4);
            }

            ANNWrapper.PrintBPParameters(Application.StartupPath + "\\" + textParas.Text + "Print.txt");
        }
Пример #3
0
        private void button10_Click(object sender, EventArgs e)
        {
            int loop = Int32.Parse(textLoop.Text);

            while (loop > 0)
            {
                loop--;

                try
                {
                    int[] intRes = new int[64];

                    ANNWrapper.BlackWhiteBMP(Application.StartupPath + "\\" + textToPath.Text, Int32.Parse(textInputInt.Text));

                    IntPtr hdibHandle = ANNWrapper.ReadDIBFile(Application.StartupPath + "\\" + textToPath.Text);

                    ANNWrapper.Convert256toGray(hdibHandle);

                    ANNWrapper.SaveDIB(hdibHandle, Application.StartupPath + "\\Convert256toGray.bmp");

                    ANNWrapper.ConvertGrayToWhiteBlack(hdibHandle);

                    ANNWrapper.SaveDIB(hdibHandle, Application.StartupPath + "\\ConvertGrayToWhiteBlack.bmp");

                    //ANNWrapper.GradientSharp(hdibHandle);
                    ANNWrapper.RemoveScatterNoise(hdibHandle);

                    ANNWrapper.SaveDIB(hdibHandle, Application.StartupPath + "\\RemoveScatterNoise.bmp");

                    //ANNWrapper.SlopeAdjust(hdibHandle);

                    Int32 charRectID = ANNWrapper.CharSegment(hdibHandle);

                    if (charRectID >= 0)
                    {
                        ANNWrapper.LoadBPParameters(Application.StartupPath + "\\" + textParas.Text);

                        //ANNWrapper.StdDIBbyRect(hdibHandle, charRectID, 16, 16);
                        IntPtr newHdibHandle = ANNWrapper.AutoAlign(hdibHandle, charRectID);
                        ANNWrapper.SaveDIB(newHdibHandle, Application.StartupPath + "\\AutoAlign.bmp");
                        //charRectID = ANNWrapper.CharSegment(newHdibHandle);

                        if (charRectID >= 0)
                        {
                            //ANNWrapper.SaveSegment(newHdibHandle, charRectID, Application.StartupPath + "\\");
                            if (ANNWrapper.Recognition_EX(newHdibHandle, charRectID, intRes))
                            {
                                string res = "";
                                foreach (int value in intRes)
                                {
                                    if (value == -1)
                                    {
                                        break;
                                    }
                                    res += value.ToString();
                                }

                                textUnMatch.AppendText(res.ToString() + "\r\n");
                            }
                            else
                            {
                                textUnMatch.AppendText("Recognition Failure" + "\r\n");
                            }
                        }

                        ANNWrapper.ReleaseDIBFile(newHdibHandle);
                    }
                    else
                    {
                        textUnMatch.AppendText("CharSegment Step False" + "\r\n");
                    }

                    ANNWrapper.ReleaseDIBFile(hdibHandle);
                }
                catch (Exception exp)
                {
                    textUnMatch.AppendText(textToPath.Text + "\r\n");
                }
            }
        }
Пример #4
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            if (textParas.Text.Length < 1)
            {
                MessageBox.Show("Para Setting Is Empty");
                return;
            }
            if (textTraingInputs.Lines.Length < 1)
            {
                MessageBox.Show("Test Input Is Empty");
                return;
            }

            ANNWrapper.LoadBPParameters(Application.StartupPath + "\\" + textParas.Text);
            //ANNWrapper.PrintBPParameters("C:\\TypePara.text");

            double[] inputs = new double[64];
            double[] dests  = new double[4];

            int divideFactor = Int32.Parse(textParaFactor.Text);
            int matchCount   = 0;

            Random rand        = new Random();
            Double noiseFactor = Double.Parse(textNoiseFactor.Text);

            foreach (string line in textTraingInputs.Lines)
            {
                string[] strs = line.Split(',');
                if (strs.Length != 65)
                {
                    continue;
                }

                for (int i = 0; i < 64; i++)
                {
                    inputs[i] = Double.Parse(strs[i]) / divideFactor;
                }

                //Add Noise Factor to Input
                int noiseCount = Int32.Parse(textNoiseCount.Text);
                for (int i = 0; i < noiseCount; i++)
                {
                    inputs[rand.Next(0, 63)] = noiseFactor;
                }

                /* string dest = Convert.ToString(Int32.Parse(strs[64]), 2);*/

                for (int i = 0; i < 4; i++)
                {
                    dests[i] = 0.0;
                }

                if (!ANNWrapper.Recognition(inputs, dests))
                {
                    MessageBox.Show("Recognition Error:" + line);
                    continue;
                }
                Int32 dest = 0;
                if (dests[0] > 0.5)
                {
                    dest += 1;
                }
                if (dests[1] > 0.5)
                {
                    dest += 2;
                }
                if (dests[2] > 0.5)
                {
                    dest += 4;
                }
                if (dests[3] > 0.5)
                {
                    dest += 8;
                }

                if (dest == Int32.Parse(strs[64]))
                {
                    matchCount += 1;
                }
                else
                {
                    textUnMatch.AppendText(line + "|" + dests[0].ToString() + "," + dests[1].ToString() + "," + dests[2].ToString() + "," + dests[3].ToString() + "" + "\r\n");
                }
            }
            double dblRate = matchCount * 100.0 / textTraingInputs.Lines.Length;

            MessageBox.Show("%" + dblRate.ToString() + "(" + matchCount.ToString() + "/" + textTraingInputs.Lines.Length + ")");
        }
Пример #5
0
        private void btTraining_Click(object sender, EventArgs e)
        {
            m_stop = false;
            // btTraining.Enabled = false;

            if (textParas.Text.Length > 0)
            {
                ANNWrapper.LoadBPParameters(Application.StartupPath + "\\" + textParas.Text);
            }
            else
            {
                ANNWrapper.InitBPParameters(64, 8, 4);
            }

            if (textTraingInputs.Lines.Length < 1)
            {
                return;
            }

            MessageBox.Show(textTraingInputs.Lines.Length.ToString() + " Lines!");

            int divideFactor = Int32.Parse(textParaFactor.Text);
            int count        = 0;

            ANNWrapper.InitTrainBPLearnSpeed(Double.Parse(textSpeed.Text));
            double accpt_diff = Double.Parse(textAvrgDiff.Text.ToString());

            double[] inputs = new double[64];
            double[] dests  = new double[4];
            while (true)
            {
                double this_dif = 0.0;
                foreach (string line in textTraingInputs.Lines)
                {
                    count++;

                    string[] strs = line.Split(',');
                    if (strs.Length != 65)
                    {
                        continue;
                    }

                    for (int i = 0; i < 64; i++)
                    {
                        inputs[i] = Double.Parse(strs[i]) / divideFactor;
                    }

                    string dest = Convert.ToString(Int32.Parse(strs[64]), 2);

                    if (dest.Length > 0 && dest[dest.Length - 1 - 0] == '1')
                    {
                        dests[0] = 1.0;
                    }
                    else
                    {
                        dests[0] = 0.0;
                    }

                    if (dest.Length > 1 && dest[dest.Length - 1 - 1] == '1')
                    {
                        dests[1] = 1.0;
                    }
                    else
                    {
                        dests[1] = 0.0;
                    }

                    if (dest.Length > 2 && dest[dest.Length - 1 - 2] == '1')
                    {
                        dests[2] = 1.0;
                    }
                    else
                    {
                        dests[2] = 0.0;
                    }

                    if (dest.Length > 3 && dest[dest.Length - 1 - 3] == '1')
                    {
                        dests[3] = 1.0;
                    }
                    else
                    {
                        dests[3] = 0.0;
                    }

                    double dif = ANNWrapper.Training(inputs, dests);
                    this_dif += dif;
                }

                this_dif /= textTraingInputs.Lines.Length;

                if (chkAutoSave.Checked)
                {
                    if (textParas.Text.Length < 1)
                    {
                        textParas.Text = "Training.dat";
                    }

                    ANNWrapper.SaveBPParameters(Application.StartupPath + "\\" + textParas.Text);
                }
                textUnMatch.AppendText(this_dif.ToString() + "\r\n");
                btTraining.Text = this_dif.ToString();
                btTraining.Update();
                if (this_dif <= accpt_diff || m_stop == true)
                {
                    ANNWrapper.SaveBPParameters(Application.StartupPath + "\\" + textParas.Text);
                    break;
                }
            }
            btTraining.Enabled = true;
            btTraining.Text    = "Train(" + count.ToString() + ")";
        }
Пример #6
0
        private void button7_Click(object sender, EventArgs e)
        {
            if (textParas.Text.Length > 0)
            {
                ANNWrapper.LoadBPParameters(Application.StartupPath + "\\" + textParas.Text);
            }
            else
            {
                ANNWrapper.InitBPParameters(64, 8, 4);
            }


            DirectoryInfo Dir = new DirectoryInfo(Application.StartupPath + "\\" + textBMPFolders.Text);

            try
            {
                foreach (DirectoryInfo d in Dir.GetDirectories())
                {
                    if (d.ToString() == "BMP0")
                    {
                        EncodeBMPs(d, 0);
                    }
                    else if (d.ToString() == "BMP1")
                    {
                        EncodeBMPs(d, 1);
                    }
                    else if (d.ToString() == "BMP2")
                    {
                        EncodeBMPs(d, 2);
                    }
                    else if (d.ToString() == "BMP3")
                    {
                        EncodeBMPs(d, 3);
                    }
                    else if (d.ToString() == "BMP4")
                    {
                        EncodeBMPs(d, 4);
                    }
                    else if (d.ToString() == "BMP5")
                    {
                        EncodeBMPs(d, 5);
                    }
                    else if (d.ToString() == "BMP6")
                    {
                        EncodeBMPs(d, 6);
                    }
                    else if (d.ToString() == "BMP7")
                    {
                        EncodeBMPs(d, 7);
                    }
                    else if (d.ToString() == "BMP8")
                    {
                        EncodeBMPs(d, 8);
                    }
                    else if (d.ToString() == "BMP9")
                    {
                        EncodeBMPs(d, 9);
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }