Example #1
0
        public static void EvaluateRectObjects(string gt_dir, string auto_dir)
        {
            int gt_count_total = 0, auto_count_total = 0, matched_count_total = 0;

            string[] gt_xml_files = Directory.GetFiles(gt_dir, "*.xml");
            using (StreamWriter sw = new StreamWriter("Evaluation.txt"))
            {
                sw.WriteLine("FigureName\tGT Panels\tAuto Panels\tMatched Panels");
                for (int i = 0; i < gt_xml_files.Length; i++)
                {
                    string gt_xml_file   = gt_xml_files[i];
                    string auto_xml_file = Path.Combine(auto_dir, Path.GetFileName(gt_xml_file).Replace("_data.xml", ".xml"));
                    if (!File.Exists(auto_xml_file))
                    {
                        continue;
                    }

                    iPhotoDrawAnnotation        gt_annotation   = new iPhotoDrawAnnotation(); gt_annotation.LoadRectObjects(gt_xml_file);
                    PanelSegmentationAnnotation auto_annotation = new PanelSegmentationAnnotation(); auto_annotation.LoadRectObjects(auto_xml_file);

                    int gt_count, auto_count, matched_count;
                    ObjectAnnotation.EvaluateRectObjects(gt_annotation, auto_annotation, out gt_count, out auto_count, out matched_count);
                    sw.WriteLine("{0}\t{1}\t{2}\t{3}", gt_annotation.figureFilename, gt_count, auto_count, matched_count);

                    gt_count_total      += gt_count;
                    auto_count_total    += auto_count;
                    matched_count_total += matched_count;
                }

                double recall    = (double)matched_count_total / (double)gt_count_total;
                double precision = (double)matched_count_total / (double)auto_count_total;
                double fscore    = 2 * precision * recall / (precision + recall);

                sw.WriteLine("Total\t{0}\t{1}\t{2}", gt_count_total, auto_count_total, matched_count_total);
                sw.WriteLine("Precision is {0}", precision);
                sw.WriteLine("Recall is {0}", recall);
                sw.WriteLine("FScore is {0}", fscore);
            }
        }
Example #2
0
        public void SaveRectObjectIniPhotoDrawFormat(string xml_file)
        {
            iPhotoDrawAnnotation iphotodraw = new iPhotoDrawAnnotation();

            iphotodraw.CreateDocumentTemplate();
            for (int i = 0; i < rectObjects.Count; i++)
            {
                iphotodraw.AddRectObjectAnnotationToDocument(rectObjects[i]);
            }

            //HTMLAgilityPack is designed for HTML, which is case-insensitive, so we have to convert certain tags to its original case.
            string xml_string = iphotodraw.doc.DocumentNode.InnerHtml;

            xml_string = xml_string.Replace(" align=", " Align=");
            xml_string = xml_string.Replace(" righttoleft=", " RightToLeft=");
            xml_string = xml_string.Replace(" left=", " Left=");
            xml_string = xml_string.Replace(" top=", " Top=");
            xml_string = xml_string.Replace(" right=", " Right=");
            xml_string = xml_string.Replace(" bottom=", " Bottom=");
            xml_string = xml_string.Replace(" x=", " X=");
            xml_string = xml_string.Replace(" y=", " Y=");
            xml_string = xml_string.Replace(" width=", " Width=");
            xml_string = xml_string.Replace(" height=", " Height=");
            xml_string = xml_string.Replace(" isroundcorner=", " IsRoundCorner=");
            xml_string = xml_string.Replace(" roundcornerradius=", " RoundCornerRadius=");
            xml_string = xml_string.Replace(" rotation=", " Rotation=");
            xml_string = xml_string.Replace(" b=", " B=");
            xml_string = xml_string.Replace(" g=", " G=");
            xml_string = xml_string.Replace(" r=", " R=");
            xml_string = xml_string.Replace(" alpha=", " Alpha=");
            xml_string = xml_string.Replace(" visible=", " Visible=");
            xml_string = xml_string.Replace(" name=", " Name=");
            xml_string = xml_string.Replace(" isnegative=", " IsNegative=");
            xml_string = xml_string.Replace(" verticalflip=", " VerticalFlip=");
            xml_string = xml_string.Replace(" horizontalflip=", " HorizontalFlip=");
            xml_string = xml_string.Replace(" type=", " Type=");
            xml_string = xml_string.Replace(" style=", " Style=");
            xml_string = xml_string.Replace(" size=", " Size=");
            xml_string = xml_string.Replace(" outlinetype=", " OutlineType=");
            xml_string = xml_string.Replace(" join=", " Join=");
            xml_string = xml_string.Replace(" dash=", " Dash=");
            xml_string = xml_string.Replace(" heightfactor=", " HeightFactor=");
            xml_string = xml_string.Replace(" widthfactor=", " WidthFactor=");
            xml_string = xml_string.Replace(" angle=", " Angle=");
            xml_string = xml_string.Replace(" verticaloffset=", " VerticalOffset=");
            xml_string = xml_string.Replace(" horizontaloffset=", " HorizontalOffset=");
            xml_string = xml_string.Replace(" filltype=", " FillType=");
            xml_string = xml_string.Replace(" imagefilltype=", " ImageFillType=");
            xml_string = xml_string.Replace(" filename=", " FileName=");
            xml_string = xml_string.Replace(" zoomfactor=", " ZoomFactor=");
            xml_string = xml_string.Replace(" wrapmode=", " WrapMode=");
            xml_string = xml_string.Replace(" usetexteffect=", " UseTextEffect=");

            xml_string = xml_string.Replace("<imageoptions ", "<ImageOptions ");
            xml_string = xml_string.Replace("</imageoptions>", "</ImageOptions>");

            xml_string = xml_string.Replace("<canvas>", "<Canvas>");
            xml_string = xml_string.Replace("</canvas>", "</Canvas>");

            xml_string = xml_string.Replace("<box ", "<Box ");
            xml_string = xml_string.Replace("</box>", "</Box>");

            xml_string = xml_string.Replace("<backcolor ", "<BackColor ");
            xml_string = xml_string.Replace("</backcolor>", "</BackColor>");

            xml_string = xml_string.Replace("<flip ", "<Flip ");
            xml_string = xml_string.Replace("</flip>", "</Flip>");

            xml_string = xml_string.Replace("<shapes>", "<Shapes>");
            xml_string = xml_string.Replace("</shapes>", "</Shapes>");
            xml_string = xml_string.Replace("<shape ", "<Shape ");
            xml_string = xml_string.Replace("</shape>", "</Shape>");

            xml_string = xml_string.Replace("<settings>", "<Settings>");
            xml_string = xml_string.Replace("</settings>", "</Settings>");

            xml_string = xml_string.Replace("<font ", "<Font ");
            xml_string = xml_string.Replace("</font>", "</Font>");

            xml_string = xml_string.Replace("<line ", "<Line ");
            xml_string = xml_string.Replace("</line>", "</Line>");

            xml_string = xml_string.Replace("<color ", "<Color ");
            xml_string = xml_string.Replace("</color>", "</Color>");

            xml_string = xml_string.Replace("<startarrowhead ", "<StartArrowHead ");
            xml_string = xml_string.Replace("</startarrowhead>", "</StartArrowHead>");

            xml_string = xml_string.Replace("<endarrowhead ", "<EndArrowHead ");
            xml_string = xml_string.Replace("</endarrowhead>", "</EndArrowHead>");

            xml_string = xml_string.Replace("<layers>", "<Layers>");
            xml_string = xml_string.Replace("</layers>", "</Layers>");
            xml_string = xml_string.Replace("<layer ", "<Layer ");
            xml_string = xml_string.Replace("</layer>", "</Layer>");

            xml_string = xml_string.Replace("<fill ", "<Fill ");
            xml_string = xml_string.Replace("</fill>", "</Fill>");

            xml_string = xml_string.Replace("<fill ", "<Fill ");
            xml_string = xml_string.Replace("</fill>", "</Fill>");

            xml_string = xml_string.Replace("<gradientsettings ", "<GradientSettings ");
            xml_string = xml_string.Replace("</gradientsettings>", "</GradientSettings>");

            xml_string = xml_string.Replace("<startingcolor ", "<StartingColor ");
            xml_string = xml_string.Replace("</startingcolor>", "</StartingColor>");

            xml_string = xml_string.Replace("<endingcolor ", "<EndingColor ");
            xml_string = xml_string.Replace("</endingcolor>", "</EndingColor>");

            xml_string = xml_string.Replace("<blend>", "<Blend>");
            xml_string = xml_string.Replace("</blend>", "</Blend>");

            xml_string = xml_string.Replace("<embeddedimage ", "<EmbeddedImage ");
            xml_string = xml_string.Replace("</embeddedimage>", "</EmbeddedImage>");

            xml_string = xml_string.Replace("<stretchsettings ", "<StretchSettings ");
            xml_string = xml_string.Replace("</stretchsettings>", "</StretchSettings>");

            xml_string = xml_string.Replace("<tilesettings ", "<TileSettings ");
            xml_string = xml_string.Replace("</tilesettings>", "</TileSettings>");

            xml_string = xml_string.Replace("<offset ", "<Offset ");
            xml_string = xml_string.Replace("</offset>", "</Offset>");

            xml_string = xml_string.Replace("<imagedata>", "<ImageData>");
            xml_string = xml_string.Replace("</imagedata>", "</ImageData>");

            xml_string = xml_string.Replace("<endingcolor ", "<EndingColor ");
            xml_string = xml_string.Replace("</endingcolor>", "</EndingColor>");

            xml_string = xml_string.Replace("<texteffect ", "<TextEffect ");
            xml_string = xml_string.Replace("</texteffect>", "</TextEffect>");

            xml_string = xml_string.Replace("<blocktext ", "<BlockText ");
            xml_string = xml_string.Replace("</blocktext>", "</BlockText>");
            xml_string = xml_string.Replace("<text>", "<Text>");
            xml_string = xml_string.Replace("</text>", "</Text>");
            xml_string = xml_string.Replace("<margin ", "<Margin ");
            xml_string = xml_string.Replace("</margin>", "</Margin>");
            xml_string = xml_string.Replace("<data ", "<Data ");
            xml_string = xml_string.Replace("</data>", "</Data>");
            xml_string = xml_string.Replace("<extent ", "<Extent ");
            xml_string = xml_string.Replace("</extent>", "</Extent>");

            System.IO.File.WriteAllText(xml_file, xml_string);
        }