public ViDiReadResultList GenerateList(SegmentInput Input) /* Generate lists of all relevant data: Score, X-position, width */ { ViDiReadResultList result = new ViDiReadResultList(); string readResult = ""; List <double> xpos_list = new List <double>(); //list for x-positions of start of new segment List <double> w_list = new List <double>(); //list for width of characters List <double> score_list = new List <double>(); //list for score of characters if (Input.Marking != null && Input.OcrString != null) { readResult = Input.OcrString; IBlueMarking m = Input.Marking; Point p = new Point(); int n = readResult.Length; int i = 0; while (i < n) { try { p = m.Views[0].Matches[0].Features[i].Position; //We assume only 1 model match and this model is 0 p = p.ToOriginalFromView(m.Views[0]); //Tranformation back to pixel image from Vidi image xpos_list.Add(p.X); score_list.Add(m.Views[0].Matches[0].Features[i].Score); w_list.Add(m.Views[0].Matches[0].Features[i].Size.Width); } catch { } } } else { readResult = ""; } result.Read = readResult; result.ScoreList = score_list; result.XPosList = xpos_list; result.WidthList = w_list; return(result); }
public SegmentResult Segment(SegmentInput input, double devW) { //Segment into list of Segment indexes and spaces SegmentResult result = new SegmentResult(); PreFilterResult filtered = PreFilter(input);//Filter rubbish end of string input.OcrString = filtered.OcrFiltered; ViDiReadResultList lists = GenerateList(input); //Use filtered string to generate lists double w = 0; double xCurr = 0; double xPrev = 0; int nChar = lists.Read.Length; double dev = devW; //consider space when difference between two positions is > dev * characterwidth List <double> x_list = new List <double>(); //list for width of characters x_list = lists.XPosList; List <double> w_list = new List <double>(); //list for width of characters w_list = lists.WidthList; List <double> segm_x_list = new List <double>(); //list for x-positions of start of new segment List <int> segm_i_list = new List <int>(); //list for character indexes of start of new segment List <double> space_list = new List <double>(); //list for size of spaces of segment if (nChar > 0 && x_list.Count == w_list.Count && x_list.Count == nChar) //Lists have same number of elements(should be the case) { w = w_list.Max(); //retain widest character as reference for calculating space //First segment starts at first character - index 0 for X-position xCurr = x_list[0]; segm_x_list.Add(x_list[0]); segm_i_list.Add(0); //Loop through the remaining characters --> list of index positions with start of segments xPrev = xCurr; int i = 1; //start at 1, we handled 0 above while (i < nChar) { xCurr = x_list[i]; if ((xCurr - xPrev) > (dev * w)) //consider space when difference between two positions is > dev * characterwidth -->New segment { segm_x_list.Add(xCurr); segm_i_list.Add(i); space_list.Add(xCurr - xPrev); } xPrev = xCurr; i++; } } else { // } result.Nsegments = segm_i_list.Count; //Get number of segments result.SegmentIndexList = segm_i_list; result.SpaceList = space_list; result.FilteredString = lists.Read; return(result); }