Пример #1
0
        public bool NumberParse_1(string bmpFile, out string ret)
        {
            ret = string.Empty;
            IntPtr hdibHandle = IntPtr.Zero;

            try
            {
                hdibHandle = ANNWrapper.ReadDIBFile(bmpFile);
                if (hdibHandle == IntPtr.Zero)
                {
                    return(false);
                }

                int[] intRes = new int[64];

                if (ANNWrapper.Convert256toGray(hdibHandle) &&
                    ANNWrapper.ConvertGrayToWhiteBlack(hdibHandle) &&
                    ANNWrapper.RemoveScatterNoise(hdibHandle))
                {
                    Int32 charRectID = ANNWrapper.CharSegment(hdibHandle);

                    if (charRectID >= 0)
                    {
                        IntPtr newHdibHandle = ANNWrapper.AutoAlign(hdibHandle, charRectID);

                        if (newHdibHandle != IntPtr.Zero && ANNWrapper.Recognition_EX(newHdibHandle, charRectID, intRes))
                        {
                            foreach (int value in intRes)
                            {
                                if (value == -1)
                                {
                                    break;
                                }
                                else if (value >= 10)
                                {
                                    ret = string.Empty;
                                    break;
                                }
                                ret += value.ToString();
                            }
                        }
                        ANNWrapper.ReleaseDIBFile(newHdibHandle);
                    }
                }
            }
            catch (System.Exception e)
            {
            }

            if (hdibHandle != IntPtr.Zero)
            {
                ANNWrapper.ReleaseDIBFile(hdibHandle);
            }

            return(!string.IsNullOrEmpty(ret));
        }
Пример #2
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");
                }
            }
        }