public IEnumerable <OcrLine> GetLines(IEnumerable <OcrWord> words, IDictionary <string, string> options) { var lines = new List <OcrLine>(); var sorted = words.OrderBy(i => i.Location.Y).ThenBy(i => i.Location.X).ToList(); var topOffSet = GetTopOffset(options); var bottomOffSet = GetBottomOffset(options); var id = 1; while (sorted.Count > 0) { var item = sorted.First(); var minY = (int)(item.Location.Y); var maxY = (int)(item.Location.YBound); if (topOffSet != 0) { minY = (int)(minY * topOffSet); } if (bottomOffSet != 0) { maxY = (int)(maxY * bottomOffSet); } var wordsInLine = sorted.Where(i => (i.Id != item.Id) && (i.Location.Y >= minY && i.Location.YBound <= maxY)).OrderBy(i => i.Location.X).ToList(); wordsInLine.Insert(0, item); lines.Add(new OcrLine() { Id = id, Words = wordsInLine.OrderBy(i => i.Location.X).ToList(), Location = OcrLoaderHelper.GetLineLocation(wordsInLine) }); wordsInLine.ForEach(i => sorted.Remove(i)); } return(lines); }
public IEnumerable <OcrLine> GetLines(IEnumerable <OcrWord> words, IDictionary <string, string> options) { var top = GetValue(options, "topRelativeRange"); var bottom = GetValue(options, "bottomRelativeRange"); var lines = new List <OcrLine>(); var sorted = words.OrderBy(i => i.Location.Y).ThenBy(i => i.Location.X).ToList(); var id = 1; while (sorted.Count > 0) { var item = sorted.First(); var minY = (int)(item.Location.Y - (item.Location.Y * top)); var maxY = (int)(item.Location.Y + (item.Location.Y * bottom)); var wordsInLine = sorted.Where(i => (i.Id != item.Id) && (i.Location.Y >= minY && i.Location.Y <= maxY)).OrderBy(i => i.Location.X).ToList(); wordsInLine.Insert(0, item); lines.Add(new OcrLine() { Id = id, Words = wordsInLine.OrderBy(i => i.Location.X).ToList(), Location = OcrLoaderHelper.GetLineLocation(wordsInLine) }); wordsInLine.ForEach(i => sorted.Remove(i)); } return(lines); }
public IEnumerable <OcrLine> GetLines(IEnumerable <OcrWord> words, IDictionary <string, string> options) { var lines = new List <OcrLine>(); var sorted = words.OrderBy(i => i.Location.Y).ThenBy(i => i.Location.X).ToList(); var id = 1; var offset = GetOffset(options); while (sorted.Count > 0) { var item = sorted.First(); var minY = (int)(item.Location.Y - (item.Location.Y * HorizontalLineMargin)); var maxY = (int)(item.Location.YBound + (item.Location.YBound * HorizontalLineMargin)); var mid = ((int)((maxY - minY) / 2)) + minY; if (offset != 0) { mid = Convert.ToInt32(mid * offset); } var wordsInLine = sorted.Where(i => (i.Id != item.Id) && (i.Location.Y <= mid && i.Location.YBound >= mid)) .OrderBy(i => i.Location.X).ToList(); wordsInLine.Insert(0, item); lines.Add(new OcrLine() { Id = id, Words = wordsInLine.OrderBy(i => i.Location.X).ToList(), Location = OcrLoaderHelper.GetLineLocation(wordsInLine) }); wordsInLine.ForEach(i => sorted.Remove(i)); } return(lines); }
public static List <OcrLine> GetLines2(List <OcrWord> words, OcrRegion region, ImageInfo info) { var lineId = 1; var lines = new List <OcrLine>(); var horLines = new List <OcrLine>(); //var horLines = Navigator.GetWordsHorizontallyAligned2(words, HorizontalLineMargin); foreach (var line in horLines) { line.ParentRegion = region; //line.Location.X = line.Words.Min(i => i.Location.X); //line.Location.Y = line.Words.Max(i => i.Location.Y); //line.Location.Height = line.Words.Max(i => i.Location.YBound) - line.Location.Y; //line.Location.Width = line.Words.Max(i => i.Location.XBound) - line.Location.X; line.Location = GetLocationFromElements(line.Words); line.Code = OcrLoaderHelper.GetLineCode(lineId, region); lines.Add(line); lineId++; } return(lines); }