コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xml_file"></param>
        public override void LoadRectObjects(string xml_file)
        {
            figureFilename = System.IO.Path.GetFileNameWithoutExtension(xml_file);

            Load(xml_file);

            rectObjects = new List <RectObject>();
            for (int i = 0; i < panels.Count; i++)
            {
                PanelSegInfo panel = panels[i];

                if (panel.panelRect.IsEmpty)
                {
                    continue;
                }

                RectObject rect_panel = new RectObject("panel " + panel.panelLabel, panel.panelRect);
                rectObjects.Add(rect_panel);

                if (panel.labelRect.IsEmpty)
                {
                    continue;
                }

                RectObject rect_label = new RectObject("label " + panel.panelLabel, panel.labelRect);
                rectObjects.Add(rect_label);
            }
        }
コード例 #2
0
        public override void LoadRectObjects(string xml_file)
        {
            rectObjects = new List <RectObject>();
            doc         = new HtmlDocument(); doc.Load(xml_file);

            HtmlNodeCollection object_nodes = doc.DocumentNode.SelectNodes("//object");

            foreach (HtmlAgilityPack.HtmlNode object_node in object_nodes)
            {
                HtmlNode name_node = object_node.SelectSingleNode("./name");
                string   name      = name_node.InnerText.Trim();

                List <PointF>      points       = new List <PointF>();
                HtmlNode           polygon_node = object_node.SelectSingleNode("./polygon");
                HtmlNodeCollection pt_nodes     = polygon_node.SelectNodes("./pt");
                foreach (HtmlNode pt_node in pt_nodes)
                {
                    HtmlNode x_node = pt_node.SelectSingleNode("./x");
                    HtmlNode y_node = pt_node.SelectSingleNode("./y");
                    string   x      = x_node.InnerText.Trim();
                    string   y      = y_node.InnerText.Trim();

                    PointF point = new PointF(float.Parse(x), float.Parse(y));
                    points.Add(point);
                }
                Rectangle rect = Emgu.CV.PointCollection.BoundingRectangle(points.ToArray());
                rect.Width -= 1; rect.Height -= 1; //Make the rect 1 pixel smaller.

                RectObject rect_object = new RectObject(name, rect);
                rectObjects.Add(rect_object);
            }
        }
コード例 #3
0
        public override void LoadRectObjects(string xml_file)
        {
            figureFilename = System.IO.Path.GetFileName(xml_file).Replace("_data.xml", "");

            rectObjects = new List <RectObject>();
            HtmlDocument doc = new HtmlDocument(); doc.Load(xml_file);

            HtmlNodeCollection shape_nodes = doc.DocumentNode.SelectNodes("//shape");

            foreach (HtmlAgilityPack.HtmlNode shape_node in shape_nodes)
            {
                HtmlNode block_text_node = shape_node.SelectSingleNode(".//blocktext");
                HtmlNode text_node       = block_text_node.SelectSingleNode("./text");
                string   label           = text_node.InnerText.Trim().ToLower();

                HtmlNode  data_node   = shape_node.SelectSingleNode(".//data");
                HtmlNode  extent_node = data_node.SelectSingleNode("./extent");
                string    x           = extent_node.GetAttributeValue("X", "");
                string    y           = extent_node.GetAttributeValue("Y", "");
                string    width       = extent_node.GetAttributeValue("Width", "");
                string    height      = extent_node.GetAttributeValue("Height", "");
                Rectangle rect        = new Rectangle((int)(float.Parse(x) + 0.5), (int)(float.Parse(y) + 0.5), (int)(float.Parse(width) + 0.5), (int)(float.Parse(height) + 0.5));

                RectObject rect_object = new RectObject(label, rect);
                rectObjects.Add(rect_object);
            }
        }
コード例 #4
0
        /// <summary>
        /// Load Panel Rects Only, no Panel Labels yet.
        /// </summary>
        /// <param name="xml_file"></param>
        public override void LoadRectObjects(string xml_file)
        {
            figureFilename = System.IO.Path.GetFileNameWithoutExtension(xml_file);

            rectObjects = new List <RectObject>();
            HtmlDocument doc = new HtmlDocument(); doc.Load(xml_file);

            HtmlNodeCollection rectangle_nodes = doc.DocumentNode.SelectNodes("//rectangle");

            foreach (HtmlAgilityPack.HtmlNode rectangle_node in rectangle_nodes)
            {
                HtmlNode  x_node      = rectangle_node.SelectSingleNode("./x");
                HtmlNode  y_node      = rectangle_node.SelectSingleNode("./y");
                HtmlNode  width_node  = rectangle_node.SelectSingleNode("./width");
                HtmlNode  height_node = rectangle_node.SelectSingleNode("./height");
                string    x           = x_node.InnerText.Trim();
                string    y           = y_node.InnerText.Trim();
                string    width       = width_node.InnerText.Trim();
                string    height      = height_node.InnerText.Trim();
                Rectangle rect        = new Rectangle(int.Parse(x), int.Parse(y), int.Parse(width), int.Parse(height));

                RectObject rect_object = new RectObject("", rect);
                rectObjects.Add(rect_object);
            }
        }
コード例 #5
0
        /// <summary>
        /// Add a rectangle object annotation to the document.
        /// </summary>
        /// <param name="rect_object"></param>
        internal void AddRectObjectAnnotationToDocument(RectObject rect_object)
        {
            HtmlNode shape_node = doc.CreateElement("Shape");

            shape_node.Attributes.Add("Type", "Rectangle");

            HtmlNode settings_node = doc.CreateElement("Settings");

            HtmlNode font_node = doc.CreateElement("Font");

            font_node.Attributes.Add("Name", "Arial");
            font_node.Attributes.Add("Style", "Regular");
            font_node.Attributes.Add("Size", "12");

            HtmlNode font_color_node = doc.CreateElement("Color");

            font_color_node.Attributes.Add("B", "0");
            font_color_node.Attributes.Add("G", "0");
            font_color_node.Attributes.Add("R", "0");
            font_color_node.Attributes.Add("Alpha", "255");

            HtmlNode line_node = doc.CreateElement("Line");

            line_node.Attributes.Add("Width", "1");
            line_node.Attributes.Add("OutlineType", "Color");
            line_node.Attributes.Add("Join", "Round");
            line_node.Attributes.Add("Dash", "Solid");

            HtmlNode line_color_node = doc.CreateElement("Color");

            if (rect_object.Name.StartsWith("label"))
            {
                line_color_node.Attributes.Add("B", "234");
                line_color_node.Attributes.Add("G", "22");
                line_color_node.Attributes.Add("R", "30");
                line_color_node.Attributes.Add("Alpha", "255");
            }
            else
            {
                line_color_node.Attributes.Add("B", "30");
                line_color_node.Attributes.Add("G", "22");
                line_color_node.Attributes.Add("R", "234");
                line_color_node.Attributes.Add("Alpha", "255");
            }

            HtmlNode line_start_arrow_node = doc.CreateElement("StartArrowHead");

            line_start_arrow_node.Attributes.Add("Type", "None");
            line_start_arrow_node.Attributes.Add("WidthFactor", "2");
            line_start_arrow_node.Attributes.Add("HeightFactor", "1");

            HtmlNode line_end_arrow_node = doc.CreateElement("EndArrowHead");

            line_end_arrow_node.Attributes.Add("Type", "None");
            line_end_arrow_node.Attributes.Add("WidthFactor", "2");
            line_end_arrow_node.Attributes.Add("HeightFactor", "1");

            HtmlNode fill_node = doc.CreateElement("Fill");

            fill_node.Attributes.Add("FillType", "None");

            HtmlNode fill_color_node = doc.CreateElement("Color");

            fill_color_node.Attributes.Add("B", "255");
            fill_color_node.Attributes.Add("G", "255");
            fill_color_node.Attributes.Add("R", "255");
            fill_color_node.Attributes.Add("Alpha", "255");

            HtmlNode fill_gradient_settings_node = doc.CreateElement("GradientSettings");

            fill_gradient_settings_node.Attributes.Add("Type", "Linear");
            fill_gradient_settings_node.Attributes.Add("VerticalOffset", "0");
            fill_gradient_settings_node.Attributes.Add("HorizontalOffset", "0");
            fill_gradient_settings_node.Attributes.Add("Angle", "0");

            HtmlNode fill_gradient_starting_color_node = doc.CreateElement("StartingColor");

            fill_gradient_starting_color_node.Attributes.Add("B", "0");
            fill_gradient_starting_color_node.Attributes.Add("G", "0");
            fill_gradient_starting_color_node.Attributes.Add("R", "0");
            fill_gradient_starting_color_node.Attributes.Add("Alpha", "255");

            HtmlNode fill_gradient_ending_color_node = doc.CreateElement("EndingColor");

            fill_gradient_ending_color_node.Attributes.Add("B", "255");
            fill_gradient_ending_color_node.Attributes.Add("G", "255");
            fill_gradient_ending_color_node.Attributes.Add("R", "255");
            fill_gradient_ending_color_node.Attributes.Add("Alpha", "255");

            HtmlNode fill_gradient_blend_node = doc.CreateElement("Blend");

            HtmlNode fill_embedded_image_node = doc.CreateElement("EmbeddedImage");

            fill_embedded_image_node.Attributes.Add("Alpha", "255");
            fill_embedded_image_node.Attributes.Add("FileName", "");
            fill_embedded_image_node.Attributes.Add("ImageFillType", "Stretch");
            fill_embedded_image_node.Attributes.Add("Align", "Center");

            HtmlNode fill_embedded_image_stretch_setting_node = doc.CreateElement("StretchSettings");

            fill_embedded_image_stretch_setting_node.Attributes.Add("Type", "KeepOriginalSize");
            fill_embedded_image_stretch_setting_node.Attributes.Add("Align", "Center");
            fill_embedded_image_stretch_setting_node.Attributes.Add("ZoomFactor", "100");

            HtmlNode fill_embedded_image_stretch_setting_offset_node = doc.CreateElement("Offset");

            fill_embedded_image_stretch_setting_offset_node.Attributes.Add("Y", "0");
            fill_embedded_image_stretch_setting_offset_node.Attributes.Add("X", "0");

            HtmlNode fill_embedded_image_tile_setting_node = doc.CreateElement("TileSettings");

            fill_embedded_image_tile_setting_node.Attributes.Add("WrapMode", "Tile");

            HtmlNode fill_embedded_image_tile_setting_offset_node = doc.CreateElement("Offset");

            fill_embedded_image_tile_setting_offset_node.Attributes.Add("Y", "0");
            fill_embedded_image_tile_setting_offset_node.Attributes.Add("X", "0");

            HtmlNode fill_embedded_image_image_data_node = doc.CreateElement("ImageData");

            HtmlNode text_effect_node = doc.CreateElement("TextEffect");

            text_effect_node.Attributes.Add("UseTextEffect", "False");

            HtmlNode block_text_node = doc.CreateElement("BlockText");

            block_text_node.Attributes.Add("Align", "Center");
            block_text_node.Attributes.Add("RightToLeft", "No");

            HtmlNode     text_node       = doc.CreateElement("Text");
            HtmlTextNode text_value_node = doc.CreateTextNode(rect_object.Name);

            HtmlNode margin_node = doc.CreateElement("Margin");

            margin_node.Attributes.Add("Top", "0");
            margin_node.Attributes.Add("Left", "0");
            margin_node.Attributes.Add("Bottom", "0");
            margin_node.Attributes.Add("Right", "0");

            HtmlNode data_node = doc.CreateElement("Data");

            data_node.Attributes.Add("Rotation", "0");
            data_node.Attributes.Add("RoundCornerRadius", "0");
            data_node.Attributes.Add("IsRoundCorner", "False");

            HtmlNode extent_node = doc.CreateElement("Extent");

            extent_node.Attributes.Add("Height", rect_object.Rect.Height.ToString());
            extent_node.Attributes.Add("Width", rect_object.Rect.Width.ToString());
            extent_node.Attributes.Add("Y", rect_object.Rect.Y.ToString());
            extent_node.Attributes.Add("X", rect_object.Rect.X.ToString());

            HtmlNode shapes_node = doc.DocumentNode.SelectSingleNode("//shapes");

            shapes_node.AppendChild(shape_node);
            shape_node.AppendChild(settings_node);
            settings_node.AppendChild(font_node);
            font_node.AppendChild(font_color_node);
            settings_node.AppendChild(line_node);
            line_node.AppendChild(line_color_node);
            line_node.AppendChild(line_start_arrow_node);
            line_node.AppendChild(line_end_arrow_node);
            settings_node.AppendChild(fill_node);
            fill_node.AppendChild(fill_color_node);
            fill_node.AppendChild(fill_gradient_settings_node);
            fill_gradient_settings_node.AppendChild(fill_gradient_starting_color_node);
            fill_gradient_settings_node.AppendChild(fill_gradient_ending_color_node);
            fill_gradient_settings_node.AppendChild(fill_gradient_blend_node);
            fill_node.AppendChild(fill_embedded_image_node);
            fill_embedded_image_node.AppendChild(fill_embedded_image_stretch_setting_node);
            fill_embedded_image_stretch_setting_node.AppendChild(fill_embedded_image_stretch_setting_offset_node);
            fill_embedded_image_node.AppendChild(fill_embedded_image_tile_setting_node);
            fill_embedded_image_tile_setting_node.AppendChild(fill_embedded_image_tile_setting_offset_node);
            fill_embedded_image_node.AppendChild(fill_embedded_image_image_data_node);
            settings_node.AppendChild(text_effect_node);
            shape_node.AppendChild(block_text_node);
            block_text_node.AppendChild(text_node);
            text_node.AppendChild(text_value_node);
            block_text_node.AppendChild(margin_node);
            shape_node.AppendChild(data_node);
            data_node.AppendChild(extent_node);
        }
コード例 #6
0
        private static void EvaluateRectObjects(ObjectAnnotation gt_annotation, ObjectAnnotation auto_annotation, out int gt_count, out int auto_count, out int matched_count)
        {
            RectObject[] gt_rect_objs   = gt_annotation.rectObjects.ToArray();
            RectObject[] auto_rect_objs = auto_annotation.rectObjects.ToArray();

            gt_count = 0;  bool[] auto_matched = new bool[auto_rect_objs.Length];

            for (int i = 0; i < gt_rect_objs.Length; i++)
            {
                RectObject gt_rect_obj = gt_rect_objs[i];
                if (!gt_rect_obj.Name.ToLower().Trim().StartsWith("panel"))
                {
                    continue;                                                         //We are not evaluating labels yet.
                }
                gt_count++;

                //Search auto annotation to find matches
                for (int j = 0; j < auto_rect_objs.Length; j++)
                {
                    RectObject auto_rect_obj = auto_rect_objs[j];

                    {//Criteria 1: Rectangle overlapping is larger than 75%
                        Rectangle overlapping_rect = Rectangle.Intersect(gt_rect_obj.Rect, auto_rect_obj.Rect);
                        double    overlapping_area = overlapping_rect.Width * overlapping_rect.Height;
                        double    gt_area          = gt_rect_obj.Rect.Width * gt_rect_obj.Rect.Height;
                        if (overlapping_area / gt_area < 0.75)
                        {
                            continue;
                        }
                    }

                    {//Criteria 2: Overlapping to adjacent panle of the matching reference panel is less than 5%
                        int k; for (k = 0; k < gt_rect_objs.Length; k++)
                        {
                            if (k == i)
                            {
                                continue;
                            }

                            RectObject gt_rect_obj1 = gt_rect_objs[k];
                            if (!gt_rect_obj1.Name.ToLower().Trim().StartsWith("panel"))
                            {
                                continue;                                                          //We are not evaluating labels yet.
                            }
                            Rectangle overlapping_rect = Rectangle.Intersect(gt_rect_obj1.Rect, auto_rect_obj.Rect);
                            double    overlapping_area = overlapping_rect.Width * overlapping_rect.Height;
                            double    gt_area          = gt_rect_obj1.Rect.Width * gt_rect_obj1.Rect.Height;
                            if (overlapping_area / gt_area > 0.05)
                            {
                                break;
                            }
                        }
                        if (k != gt_rect_objs.Length)
                        {
                            continue;                           //This means auto_rect_obj overlaps with an adjacent gt_rect_obj and larger than 5%.
                        }
                    }

                    auto_matched[j] = true; break;
                }
            }

            //Compute Precision and Recall
            auto_count    = auto_rect_objs.Length;
            matched_count = 0; for (int i = 0; i < auto_matched.Length; i++)
            {
                if (auto_matched[i])
                {
                    matched_count++;
                }
            }
        }