private void button13_Click(object sender, EventArgs e) { try { DirectoryInfo DirNew = new DirectoryInfo(Application.StartupPath + "\\" + textBMPFolders.Text + "\\BMPFolders"); if (!DirNew.Exists) { DirNew.Create(); } DirectoryInfo Dir = new DirectoryInfo(Application.StartupPath + "\\" + textBMPFolders.Text); foreach (FileInfo f in Dir.GetFiles("*.bmp")) { textToPath.Text = textBMPFolders.Text + "\\" + f.Name; //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) { IntPtr newHdibHandle = ANNWrapper.AutoAlign(hdibHandle, charRectID); ANNWrapper.SaveDIB(newHdibHandle, Application.StartupPath + "\\AutoAlign.bmp"); ANNWrapper.SaveSegment(newHdibHandle, charRectID, Application.StartupPath + "\\" + textBMPFolders.Text + "\\BMPFolders"); ANNWrapper.ReleaseDIBFile(newHdibHandle); } else { MessageBox.Show("CharSegment Step Failure !"); } ANNWrapper.ReleaseDIBFile(hdibHandle); } } catch (Exception exp) { MessageBox.Show(textToPath.Text); } }
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)); }
private void button9_Click(object sender, EventArgs e) { DirectoryInfo Dir = new DirectoryInfo(Application.StartupPath + "\\"); foreach (FileInfo f in Dir.GetFiles("*Capture.bmp")) { try { textToPath.Text = f.Name; 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.StdDIBbyRect(hdibHandle, charRectID, 16, 16); IntPtr newHdibHandle = ANNWrapper.AutoAlign(hdibHandle, charRectID); ANNWrapper.SaveSegment(newHdibHandle, charRectID, Application.StartupPath + "\\"); ANNWrapper.ReleaseDIBFile(newHdibHandle); } else { MessageBox.Show("CharSegment Step False"); } ANNWrapper.ReleaseDIBFile(hdibHandle); } catch (Exception exp) { MessageBox.Show(textToPath.Text); } } }
private void EncodeBMPs(DirectoryInfo Dir, int dest) { double[] dblEncode = new double[64]; try { string gridFile = Dir.FullName + "\\Grid.text"; FileInfo fGrid = new FileInfo(gridFile); fGrid.Delete(); fGrid = null; foreach (FileInfo f in Dir.GetFiles("*.bmp")) { IntPtr hdibHandle = ANNWrapper.ReadDIBFile(f.FullName); if (ANNWrapper.BPEncode(hdibHandle, dblEncode, 0, 0, 0, 0, gridFile)) { string strCodes = ""; foreach (double dblValue in dblEncode) { strCodes += dblValue.ToString() + ","; } strCodes += dest.ToString(); if (textTraingInputs.Lines.Length == 0) { textTraingInputs.AppendText(strCodes); } else { textTraingInputs.AppendText("\r\n" + strCodes); } } ANNWrapper.ReleaseDIBFile(hdibHandle); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
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"); } } }