public void Interpret(InterpretArgs args) { Bitmap pixels = (Bitmap)args.Tree["capturedpixels"]; if (featureTree != null) { List <Tree> found = new List <Tree>(); if (args.Tree.HasTag("invalidated")) { IBoundingBox invalidated = args.Tree["invalidated"] as IBoundingBox; if (invalidated != null && !BoundingBox.Equals(invalidated, args.Tree) && args.Tree.HasTag("previous") && args.Tree["previous"] != null) { featureTree.MatchInvalidatedRegion(pixels, found, _prevFeatures, invalidated); } else { featureTree.MultiThreadedMatch(pixels, found); } } else { featureTree.MultiThreadedMatch(pixels, found); } foreach (Tree f in found) { args.SetAncestor(f, args.Tree); } } }
public static void SetAncestorsByContainment(List <Tree> nodes, InterpretArgs args) { nodes.Sort(CompareByAreaAndFeaturesFirst); for (int i = 0; i < nodes.Count - 1; i++) { Tree curr = nodes[i]; for (int j = i + 1; j < nodes.Count; j++) { Tree next = nodes[j]; if (BoundingBox.IsInsideInclusive(curr, next)) { args.SetAncestor(curr, next); } } } }
/// <summary> /// Finds the unpredictable content using the backround regions of elements. /// </summary> /// <param name="node"></param> /// <param name="image"></param> /// <param name="background"></param> /// <param name="isForeground"></param> private static List <Tree> FindAndAddContent(InterpretArgs args, Tree node, Bitmap image, Bitmap isForeground) { Ptype ptype = (Ptype)node["ptype"]; List <Tree> allFound = new List <Tree>(); if (ptype != null) { ptype.Model.Finder.SetForeground(node, image, isForeground); } //recurse. if no siblings are overlapping (the majority case) then we can run each child in parallel. // if (!anyOverlapping(node.children())){ // List<Future<ICollection<Tree>>> asyncResults = new List<Future<ICollection<Tree>>>(); // for(final Tree child : node.children()){ // Callable<ICollection<Tree>> callable = new Callable<ICollection<Tree>>(){ // public ICollection<Tree> call(){ // return findAndAddContent(args, ptype, child, image, isForeground); // } // }; // Future<ICollection<Tree>> results = Utils.service.submit(callable); // asyncResults.add(results); // } // // for(Future<ICollection<Tree>> res : asyncResults){ // // try { // allFound.addAll(res.get()); // } catch (InterruptedException e) { // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. // } catch (ExecutionException e) { // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. // } // } // } // else //we can't run children in parallel if any nodes overlap. // //nodes only overlap when there's a false positive. so we might be able // //to trigger something here and automatically correct that. // { foreach (Tree child in node.GetChildren()) { FindAndAddContent(args, child, image, isForeground); } if (ptype != null) { ptype.Model.Finder.FindContent(node, image, isForeground, allFound); foreach (Tree found in allFound) { args.SetAncestor(found, node); } allFound.AddRange(node.GetChildren()); PrototypeDetectionLayer.SetAncestorsByContainment(allFound, args); } // } return(allFound); }
public void enqueue_set_ancestor(Tree node, Tree ancestor) { args.SetAncestor(node, ancestor); }
private void InterpretHelper(InterpretArgs args, Tree currNode) { var children = currNode.GetChildren().Where(n => n["is_text"] != null && (bool)n["is_text"]); var sorted = GroupNextLayer.SortNodesInReadingOrder(children); bool createNew = true; List <Tree> togroup = new List <Tree>(); for (int i = 1; i < sorted.Count; i++) { Tree currChild = sorted[i]; Tree prevChild = sorted[i - 1]; if (prevChild["group_next"] != null && (bool)prevChild["group_next"]) { if (createNew) { createNew = false; togroup.Add(prevChild); } togroup.Add(currChild); } else { if (togroup.Count > 0) { IBoundingBox bounding = BoundingBox.Union(togroup); var tags = new Dictionary <string, object>(); tags["type"] = "grouped_text"; tags["is_text"] = true; Tree grouped = Tree.FromBoundingBox(bounding, tags); foreach (Tree t in togroup) { args.SetAncestor(t, grouped); } args.SetAncestor(grouped, currNode); togroup.Clear(); } createNew = true; } } if (togroup.Count > 0) { IBoundingBox bounding = BoundingBox.Union(togroup); var tags = new Dictionary <string, object>(); tags["type"] = "grouped_text"; tags["is_text"] = true; Tree grouped = Tree.FromBoundingBox(bounding, tags); foreach (Tree t in togroup) { args.SetAncestor(t, grouped); } args.SetAncestor(grouped, currNode); togroup.Clear(); } foreach (Tree child in currNode.GetChildren()) { InterpretHelper(args, child); } }