Exemplo n.º 1
0
        private static void Test(string folder)
        {
            RgbHCrCbTrainee train = new RgbHCrCbTrainee();

            DirectoryInfo di = new DirectoryInfo(folder);
            if (di.Exists)
            {
                foreach (FileInfo f in di.GetFiles("*.jpg"))
                {

                    DateTime d1 = DateTime.Now;

                    FloodFillLabeler lab = new FloodFillLabeler(train, new Bitmap(f.FullName));
                    lab.AddFilter(new RemoveNoiseRegionFilter(0.01F));
                    lab.Execute();

                    Console.WriteLine("Analized: {0} sec.", (DateTime.Now - d1).TotalSeconds);

                    FaceClassifier analyse = new FaceClassifier(lab);
                    IDrawer display = new RegionDrawer(lab.Image, analyse.GetRegions());
                    display.SkinLayer = SkinLayerMode.SKIN;
                    display.InfoLayers = InfoLayerModes.INFORMATION | InfoLayerModes.CENTER;
                    display.DrawRegions().Save(f.FullName + "result.jpg");

                    Console.WriteLine("Saved: {0} sec.", (DateTime.Now - d1).TotalSeconds);
                    Console.WriteLine("");
                }
            }

            Console.Read();
        }
Exemplo n.º 2
0
        private static void Test()
        {
            string folder = @"D:\My Documents\My Pictures\NAL\Group portret\Pack\";
            DirectoryInfo di = new DirectoryInfo(folder);
            if (di.Exists)
            {
                string resultPath = Path.Combine(di.FullName, "Detected faces");
                string guid = Guid.NewGuid().ToString().Substring(0, 4);

                XmlDocument html = new XmlDocument();
                XmlNode table = html.CreateNode(XmlNodeType.Element, "table", "");

                using (StreamWriter log = new StreamWriter(Path.Combine(resultPath, "log.txt"), true))
                {
                    log.AutoFlush = true;
                    int i = 0;
                    int faceCount = 0;

                    Console.WriteLine("Name;Number;   \tA;\tS");

                    foreach (FileInfo f in di.GetFiles("*.jpg", SearchOption.TopDirectoryOnly))
                    {
                        try
                        {
                            DateTime d1 = DateTime.Now;

                            string filePath = f.FullName;

                            ITrainee train = new RgbHCrCbTrainee();

                            ILabeler lab = new FloodFillLabelerUnsafe(train, new Bitmap(filePath), 2);
                            lab.AddFilter(new RemoveNoiseRegionFilter(0.01F));
                            lab.AddFilter(new ClosingRegionFilter(MorfologicalRegionFilterBase.StructuralElement.Diamond5));
                            lab.Execute();

                            DateTime d2 = DateTime.Now;

                            IClassifier analyse = new FaceClassifier(lab);
                            SRegion[] faces = analyse.GetRegions();
                            //SRegion[] faces = lab.Regions;

                            if (faces != null)
                                faceCount += faces.Length;

                            IDrawer display = new RegionDrawer(lab.Image, faces);
                            //IDrawer display = new InterestPointDrawer(lab.Image, faces);
                            display.BackLayer = BackLayerMode.BACKGROUNDIMAGE;
                            display.SkinLayer = SkinLayerMode.SKIN;
                            display.SkinLayerTransparent = 125;
                            display.InfoLayers = InfoLayerModes.CENTER | InfoLayerModes.FRAME;

                            string filename = string.Format("{0}_{1}.jpg", guid, f.Name);
                            display.DrawRegions().Save(Path.Combine(resultPath, filename));

                            string name = string.Format("{0};{1}", f.Name, i);
                            string msg = string.Format("{2};   \t{0};\t{1}", (d2 - d1).TotalSeconds, (DateTime.Now - d2).TotalSeconds, name);
                            Console.WriteLine(msg);
                            log.WriteLine(msg);

                            XmlNode tr = html.CreateNode(XmlNodeType.Element, "tr", "");
                            XmlNode td1 = html.CreateNode(XmlNodeType.Element, "td", "");
                            XmlNode td2 = html.CreateNode(XmlNodeType.Element, "td", "");
                            XmlNode img = html.CreateNode(XmlNodeType.Element, "img", "");
                            XmlAttribute src = html.CreateAttribute("src");

                            src.Value = filename;
                            td2.InnerText = msg;

                            img.Attributes.Append(src);
                            td1.AppendChild(img);
                            tr.AppendChild(td1);
                            tr.AppendChild(td2);
                            table.AppendChild(tr);

                        }
                        catch (StackOverflowException)
                        {
                            log.WriteLine("StackOverflowException");
                        }
                        catch (OutOfMemoryException)
                        {
                            log.WriteLine("OutOfMemoryException");
                        }

                        i++;
                    }

                    log.WriteLine("{0} faces found", faceCount);
                }

                html.AppendChild(table);
                html.Save(Path.Combine(resultPath, "result.html"));
            }
            Console.WriteLine("Ready");
            //Console.Read();
        }