Пример #1
0
        private static void UnsafeTest()
        {
            DateTime d1 = DateTime.Now;

            ILabeler lab = new FloodFillLabelerUnsafe(new RgbHCrCbTrainee(), new Bitmap(@"D:\My Documents\My Pictures\NAL\Group portret\Pack\UnsafeTest\test17.jpg"), 2);
            lab.AddFilter(new RemoveNoiseRegionFilter(0.01F, false));
            lab.AddFilter(new ClosingRegionFilter(MorfologicalRegionFilterBase.StructuralElement.Diamond5));
            lab.Execute();

            Console.WriteLine(((TimeSpan)(DateTime.Now - d1)).TotalMilliseconds.ToString());
            DateTime d2 = DateTime.Now;

            IClassifier analyse = new FaceClassifier(lab);

            IDrawer dis = new RegionDrawer(lab.Image, analyse.GetRegions());
            dis.SkinLayer = SkinLayerMode.SKIN;
            dis.DrawRegions().Save(@"D:\My Documents\My Pictures\NAL\Group portret\Pack\UnsafeTest\test17d.jpg");

            Console.WriteLine(((TimeSpan)(DateTime.Now - d2)).TotalMilliseconds.ToString());
            Console.WriteLine(((TimeSpan)(DateTime.Now - d1)).TotalMilliseconds.ToString());
            Console.Read();
        }
Пример #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();
        }