public static Google.Protobuf.Collections.RepeatedField <EntityAnnotation> GetMergedLines(string[] lines, List <EntityAnnotation> rawText) { var mergedArray = new Google.Protobuf.Collections.RepeatedField <EntityAnnotation>(); var linesList = lines.ToList(); while (linesList.Count != 1) { var l = linesList.Last(); linesList.RemoveAt(linesList.Count - 1); if (String.IsNullOrEmpty(l)) { continue; } var ll = l; var status = true; EntityAnnotation mergedElement = new EntityAnnotation(); while (true) { var wElement = rawText.Last(); rawText.RemoveAt(rawText.Count - 1); var w = wElement.Description; var index = l.IndexOf(w); if (index >= 0) { // check if the word is inside l = l.Substring(index + w.Length); if (status) { status = false; // set starting coordinates mergedElement = wElement; } if (String.IsNullOrEmpty(l)) { // set ending coordinates mergedElement.Description = ll; mergedElement.BoundingPoly.Vertices[1] = wElement.BoundingPoly.Vertices[1]; mergedElement.BoundingPoly.Vertices[2] = wElement.BoundingPoly.Vertices[2]; mergedArray.Add(mergedElement); break; } } } } return(mergedArray); }
private static SpatialText ConvertToSpatialText(EntityAnnotation annotation) { var topLeft = annotation.BoundingPoly.Vertices[0]; var bottomRight = annotation.BoundingPoly.Vertices[2]; var position = new Point(topLeft.X, topLeft.Y); var size = new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); var rectangle = new Rectangle(position, size); return(new SpatialText(annotation.Description, rectangle)); }
public EntityAnnotationModel(EntityAnnotation entityAnnotation) { Description = entityAnnotation.Description; Locale = entityAnnotation.Locale; Vertices = new List <VertexModel>(); foreach (var boundingPolyVertex in entityAnnotation.BoundingPoly.Vertices) { Vertices.Add(new VertexModel(boundingPolyVertex)); } Locations = new List <LocationInfoModel>(); foreach (var location in entityAnnotation.Locations) { Locations.Add(new LocationInfoModel(location)); } }
public Box(EntityAnnotation ann, int index) { BoundingPoly bp = ann.BoundingPoly; Annotation = ann; Description = ann.Description; Index = index; Bounds = bp; Debug.Assert(bp.Vertices.Count == 4); int l = bp.Vertices.Min(x => x.X); int r = bp.Vertices.Max(x => x.X); int t = bp.Vertices.Min(x => x.Y); int b = bp.Vertices.Max(x => x.Y); Rect = new Rectangle(new Point(l, t), new Size(r - l, b - t)); LowerRight = new Point(r, b); Size = Rect.Size.Height * Rect.Size.Width; }
static List <ReceiptEntityAnnotation> GetMergedLines(List <string> lines, List <EntityAnnotation> rawText) { List <ReceiptEntityAnnotation> mergedArray = new List <ReceiptEntityAnnotation>(); while (lines.Count != 1) { string l = lines.Pop(), l1 = l, data = string.Empty; ReceiptEntityAnnotation mergedElement = null; while (rawText.Count > 0) { EntityAnnotation wElement = rawText.Pop(); string description = wElement.Description; int index = l.IndexOf(description); // check if the word is inside l = l.Substring(index + description.Length); if (mergedElement == null) { // set starting coordinates mergedElement = new ReceiptEntityAnnotation(/*wElement.BoundingPoly.Vertices*/) { Description = description, Vertices = wElement.BoundingPoly.Vertices }; } if (string.IsNullOrEmpty(l)) { // set ending coordinates mergedElement.Description = l1; mergedElement.Vertices[1] = wElement.BoundingPoly.Vertices[1]; mergedElement.Vertices[2] = wElement.BoundingPoly.Vertices[2]; mergedArray.Add(mergedElement); break; } } } return(mergedArray); }
private static GoogleWord AsWord(EntityAnnotation arg) { var vertices = arg.BoundingPoly.Vertices; var yArray = vertices.Where(x => x.Y >= 0).Select(x => x.Y).Distinct(); var xArray = vertices.Where(x => x.X >= 0).Select(x => x.X).Distinct(); if (xArray.Count() < 2 || yArray.Count() < 2) { return(null); } return(new GoogleWord() { Bottom = yArray.Max(), Top = yArray.Min(), Left = xArray.Min(), Right = xArray.Max(), Description = arg.Description }); }
public OCRBox(EntityAnnotation ann) { text = ann.Description; points = ann.BoundingPoly.Vertices.Select(Utility.ToPoint).ToArray(); }
public static DataResult f_hilight_brand_and_save_frame(Mat ar_frame, AnnotateImageResponse ar_AnnotateImageResponse, string ar_brand_name, double ar_cost_of_1_second, string ar_result_path, string ar_picture_name, int ar_second_number) { Point p = new Point(); List <Point> l_list_points = new List <Point>(); List <List <Point> > ListOfListOfPoint = new List <List <Point> >(); EntityAnnotation annotation = new EntityAnnotation(); Boolean l_at_least_1_occurence_found = false; List <DataResult> l_data_result = new List <DataResult>(); Mat l_frame = new Mat(); ar_frame.CopyTo(l_frame); int li_count_of_brand_occurences_found = 0; l_at_least_1_occurence_found = false; int li_count_of_all_occurences_found = ar_AnnotateImageResponse.TextAnnotations.Count; for (int i = 1; i < li_count_of_all_occurences_found; i++) //=== skip i=0 as it contain all occurences { annotation = ar_AnnotateImageResponse.TextAnnotations[i]; if (annotation.Description != null && annotation.Description.ToLower().Contains(ar_brand_name.ToLower())) { l_at_least_1_occurence_found = true; li_count_of_brand_occurences_found++; l_list_points.Clear(); ListOfListOfPoint.Clear(); p.X = annotation.BoundingPoly.Vertices.ElementAt(0).X; p.Y = annotation.BoundingPoly.Vertices.ElementAt(0).Y; l_list_points.Add(new Point(p.X, p.Y)); p.X = annotation.BoundingPoly.Vertices.ElementAt(1).X; p.Y = annotation.BoundingPoly.Vertices.ElementAt(1).Y; l_list_points.Add(new Point(p.X, p.Y)); p.X = annotation.BoundingPoly.Vertices.ElementAt(2).X; p.Y = annotation.BoundingPoly.Vertices.ElementAt(2).Y; l_list_points.Add(new Point(p.X, p.Y)); p.X = annotation.BoundingPoly.Vertices.ElementAt(3).X; p.Y = annotation.BoundingPoly.Vertices.ElementAt(3).Y; l_list_points.Add(new Point(p.X, p.Y)); ListOfListOfPoint.Add(l_list_points); Cv2.Polylines(l_frame, ListOfListOfPoint, true, Scalar.Red, 1); } } string l_picutre_name; if (l_at_least_1_occurence_found) { l_picutre_name = ar_picture_name + "_pm.png"; //===pm as Positive match } else { l_picutre_name = ar_picture_name + "_fm.png"; } //===fm as False match //===save picture String ls_brand_result_path = Path.Combine(ar_result_path, ar_brand_name); Directory.CreateDirectory(ls_brand_result_path); String ls_brand_result_path_and_name = Path.Combine(ls_brand_result_path, l_picutre_name); Cv2.ImWrite(ls_brand_result_path_and_name, l_frame); //===log result into DataResult DataResult l_current_data_result = new DataResult(); l_current_data_result.BrandName = ar_brand_name; l_current_data_result.FrameRef = l_picutre_name; l_current_data_result.SecondRef = ar_second_number; l_current_data_result.TotalOccurences = li_count_of_brand_occurences_found; l_current_data_result.Cost = li_count_of_brand_occurences_found * ar_cost_of_1_second; l_data_result.Add(l_current_data_result); //===return DataResult return(l_current_data_result); }
private static string BuildString(EntityAnnotation entity) { return($"{entity.Description} [{entity.Score * 100}]"); }