/// <summary> /// Des the serialise. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static HistogramLetter DeSerialise(string text) { HistogramLetter ret = null; try { var t1 = text.Split(new[] { b }, StringSplitOptions.RemoveEmptyEntries); var let = t1[0][0]; //get values var xarr = t1[1]; var xval = xarr.Split(new[] { f }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); var yarr = t1[2]; var yval = yarr.Split(new[] { f }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); //set values ret = new HistogramLetter { XValues = xval, YValues = yval, Letter = let }; } catch (ArgumentException) { } return(ret); }
/// <summary> /// Des the serialise. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> public static SymbolIdentity DeSerialise(string filename) { var ret = new SymbolIdentity(); try { var text = FileExtras.LoadFile(filename); var t1 = text.Split(new[] { v }, StringSplitOptions.RemoveEmptyEntries); var w = int.Parse(t1[0]); var h = int.Parse(t1[1]); var letters = new List <HistogramLetter>(); for (var a = 2; a < t1.Count(); a++) { var ltext = t1[a]; var l = HistogramLetter.DeSerialise(ltext); if (letters.Any(s => s.Letter.Equals(l.Letter)) == false) { letters.Add(l); } } ret.HistogramHeight = h; ret.HistogramWidth = w; ret.Letters = letters; } catch (ArgumentException) { } return(ret); }
/// <summary> /// get score. score of 0 is perfect /// </summary> /// <param name="b">The b.</param> /// <param name="l">The l.</param> /// <returns></returns> private int GetOffScore(Bitmap b, HistogramLetter l) { var bba = BitmapBoolArray.GetBitmapBoolArray(b); var h = HistogramLetter.GetHistogram(bba, b); var score = l.GetHistogramOffsetScore(h.Item1, h.Item2); return(score); }
/// <summary> /// take an image of a letter and a character of what it is, and train the ocr /// </summary> /// <param name="b">The b.</param> /// <param name="letterChar">The letter character.</param> /// <returns></returns> public bool Train(Bitmap b, char letterChar) { try { var l = new HistogramLetter(b, letterChar); Letters.Add(l); return(true); } catch (ArgumentNullException) { } return(false); }
/// <summary> /// Des the serialise. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static HistogramLetter DeSerialise(string text) { HistogramLetter ret = null; try { var t1 = text.Split(new[] { b }, StringSplitOptions.RemoveEmptyEntries); var let = t1[0][0]; //get values var xarr = t1[1]; var xval = xarr.Split(new[] { f }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); var yarr = t1[2]; var yval = yarr.Split(new[] { f }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); //set values ret = new HistogramLetter { XValues = xval, YValues = yval, Letter = let }; } catch (ArgumentException) { } return ret; }
/// <summary> /// get score. score of 0 is perfect /// </summary> /// <param name="b">The b.</param> /// <param name="l">The l.</param> /// <returns></returns> private int GetOffScore(Bitmap b, HistogramLetter l) { var bba = BitmapBoolArray.GetBitmapBoolArray(b); var h = HistogramLetter.GetHistogram(bba, b); var score = l.GetHistogramOffsetScore(h.Item1, h.Item2); return score; }
/// <summary> /// take an image of a letter and a character of what it is, and train the ocr /// </summary> /// <param name="b">The b.</param> /// <param name="letterChar">The letter character.</param> /// <returns></returns> public bool Train(Bitmap b, char letterChar) { try { var l = new HistogramLetter(b, letterChar); Letters.Add(l); return true; } catch (ArgumentNullException) { } return false; }