private void assignPredictedText2(PredictedObject predictedObject, HandwritingTextLine[] textLines) { predictedObject.Text = new List <string>(); for (int i = 0; i < textLines.Length; i++) { //if areas are 100% overlapping assign every textline Overlap ovl = new Overlap(); Entities.BoundingBox b = new Entities.BoundingBox(); int min_x = textLines[i].Polygon.Points.Min(p => p.X); int min_y = textLines[i].Polygon.Points.Min(p => p.Y); int max_x = textLines[i].Polygon.Points.Max(p => p.X); int max_y = textLines[i].Polygon.Points.Max(p => p.Y); b.Left = min_x; b.Top = min_y; b.Width = max_x - min_x; b.Height = max_y - min_y; //If boxes overlaps more than 50% we decide they are the same thing if (ovl.OverlapArea(predictedObject.BoundingBox, b) > 0.5) { for (int j = 0; j < textLines[i].Words.Length; j++) { predictedObject.Text.Add(textLines[i].Words[j].Text); } } } }
private void assignPredictedText(PredictedObject predictedObject, List <Line> textLines) { predictedObject.Text = new List <string>(); foreach (var textLine in textLines) { //if areas are 100% overlapping assign every textline Overlap ovl = new Overlap(); Entities.BoundingBox b = new Entities.BoundingBox(); // Bounding box of a recognized region, line, or word, depending on the parent object. // It's an arrary of eight numbers represent the four points (x-coordinate, y-coordinate // from the left-top corner of the image) of the detected rectangle from the left-top corner // in the clockwise direction. var xPoints = textLine.BoundingBox.Where((value, index) => index % 2 == 0).ToArray(); var yPoints = textLine.BoundingBox.Where((value, index) => index % 2 != 0).ToArray(); var min_x = xPoints.Min(); var min_y = yPoints.Min(); var max_x = xPoints.Max(); var max_y = yPoints.Max(); b.Left = min_x; b.Top = min_y; b.Width = max_x - min_x; b.Height = max_y - min_y; //If boxes overlaps more than 50% we decide they are the same thing if (ovl.OverlapArea(predictedObject.BoundingBox, b) > 0.5) { for (int j = 0; j < textLine.Words.Count; j++) { predictedObject.Text.Add(textLine.Words[j].Text); } } } }