Пример #1
0
        /// <summary>
        ///   Writes the specified cascade.
        /// </summary>
        /// <param name="cascade">The cascade to write.</param>
        /// <param name="className">The name for the generated class.</param>
        /// 
        public void Write(HaarCascade cascade, string className)
        {
            for (int i = 0; i < cascade.Stages.Length; i++)
                for (int j = 0; j < cascade.Stages[i].Trees.Length; j++)
                    if (cascade.Stages[i].Trees[j].Length != 1)
                        throw new ArgumentException("Only cascades with single node trees are currently supported.");


            writer.WriteLine("// This file has been automatically transcribed by the");
            writer.WriteLine("//");
            writer.WriteLine("// Accord Vision Library");
            writer.WriteLine("// The Accord.NET Framework");
            writer.WriteLine("// http://accord-framework.net");
            writer.WriteLine("//");
            writer.WriteLine();
            writer.WriteLine("namespace HaarCascades");
            writer.WriteLine("{");
            writer.WriteLine("    using System.CodeDom.Compiler;");
            writer.WriteLine("    using System.Collections.Generic;");
            writer.WriteLine();
            writer.WriteLine("    /// <summary>");
            writer.WriteLine("    ///   Automatically generated haar-cascade definition");
            writer.WriteLine("    ///   to use with the Accord.NET Framework object detectors.");
            writer.WriteLine("    /// </summary>");
            writer.WriteLine("    /// ");
            writer.WriteLine("    [GeneratedCode(\"Accord.NET HaarCascadeWriter\", \"2.7\")]");
            writer.WriteLine("    public class {0} : Accord.Vision.Detection.HaarCascade", className);
            writer.WriteLine("    {");
            writer.WriteLine();
            writer.WriteLine("        /// <summary>");
            writer.WriteLine("        ///   Automatically generated transcription");
            writer.WriteLine("        /// </summary>");
            writer.WriteLine("        public {0}()", className);
            writer.WriteLine("            : base({0}, {1})", cascade.Width, cascade.Height);
            writer.WriteLine("        {");
            writer.WriteLine("            List<HaarCascadeStage> stages = new List<HaarCascadeStage>();");
            writer.WriteLine("            List<HaarFeatureNode[]> nodes;");
            writer.WriteLine("            HaarCascadeStage stage;");
            writer.WriteLine();

            if (cascade.HasTiltedFeatures)
            {
                writer.WriteLine("            HasTiltedFeatures = true;");
                writer.WriteLine();
            }

            // Write cascade stages
            for (int i = 0; i < cascade.Stages.Length; i++)
                writeStage(i, cascade.Stages[i]);

            writer.WriteLine();
            writer.WriteLine("            Stages = stages.ToArray();");
            writer.WriteLine("         }");
            writer.WriteLine("    }");
            writer.WriteLine("}");
        }
Пример #2
0
 public FrmEnrollUser()
 {
     try
     {
         InitializeComponent();
         cascade = new FaceHaarCascade();
     }
     catch (Exception er)
     {
         MessageBox.Show(er.Message, "Face Detection and Recognition Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #3
0
 public FrmFaceDetection()
 {
     try
     {
         InitializeComponent();
         webcamVideo = new Capture();
         //faceDetection = new HaarCascade(Application.StartupPath + "\\haarcascade_frontalface_default.xml");
         faceDetection = new Emgu.CV.HaarCascade("haarcascade_frontalface_default.xml");
         cascade       = new FaceHaarCascade();
     }
     catch (Exception er)
     {
         MessageBox.Show(er.Message, "Face Detection and Recognition Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #4
0
        /// <summary>
        ///   Constructs a new classifier.
        /// </summary>
        ///
        public HaarClassifier(HaarCascade cascade)
        {
            this.cascade = cascade;

            var features = new List <HaarFeature>();

            // For each stage in the cascade
            foreach (HaarCascadeStage stage in cascade.Stages)
            {
                // For each tree in the cascade
                foreach (HaarFeatureNode[] tree in stage.Trees)
                {
                    // For each feature node in the tree
                    foreach (HaarFeatureNode node in tree)
                    {
                        features.Add(node.Feature);
                    }
                }
            }

            this.features = features.ToArray();
        }
Пример #5
0
        /// <summary>
        ///   Constructs a new Haar object detector.
        /// </summary>
        ///
        /// <param name="cascade">
        ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
        ///   For the default face cascade, please take a look on
        ///   <see cref="Cascades.FaceHaarCascade"/>. </param>
        /// <param name="minSize">
        ///   Minimum window size to consider when searching for
        ///   objects. Default value is <c>15</c>.</param>
        /// <param name="searchMode">The <see cref="ObjectDetectorSearchMode"/> to use
        ///   during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
        ///   for details. Default is <see cref="ObjectDetectorSearchMode.NoOverlap"/>.</param>
        /// <param name="scaleFactor">The scaling factor to rescale the window
        ///   during search. Default value is <c>1.2f</c>.</param>
        /// <param name="scalingMode">The <see cref="ObjectDetectorScalingMode"/> to use
        ///   when re-scaling the search window during search. Default is
        ///   <see cref="ObjectDetectorScalingMode.SmallerToGreater"/>.</param>
        ///
        public HaarObjectDetector(HaarCascade cascade, int minSize,
                                  ObjectDetectorSearchMode searchMode, float scaleFactor,
                                  ObjectDetectorScalingMode scalingMode)
        {
            this.classifier      = new HaarClassifier(cascade);
            this.minSize         = new Size(minSize, minSize);
            this.searchMode      = searchMode;
            this.ScalingMode     = scalingMode;
            this.factor          = scaleFactor;
            this.detectedObjects = new List <Rectangle>();

            this.baseWidth  = cascade.Width;
            this.baseHeight = cascade.Height;

            this.match = new GroupMatching(0, 0.2);

#if NET35
            this.parallel = false;
#else
            this.parallel = true;
#endif
        }
Пример #6
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// 
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        /// 
        public object Clone()
        {
            HaarCascadeStage[] newStages = new HaarCascadeStage[Stages.Length];
            for (int i = 0; i < newStages.Length; i++)
                newStages[i] = (HaarCascadeStage)Stages[i].Clone();

            HaarCascade r = new HaarCascade(Width, Height);
            r.HasTiltedFeatures = this.HasTiltedFeatures;
            r.Stages = newStages;

            return r;
        }
Пример #7
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 ///
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.
 /// </param>
 /// <param name="minSize">
 ///   Minimum window size to consider when searching for
 ///   objects. Default value is <c>15</c>.</param>
 /// <param name="searchMode">The <see cref="ObjectDetectorSearchMode"/> to use
 ///   during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
 ///   for details. Default value is <see cref="ObjectDetectorSearchMode.NoOverlap"/></param>
 ///
 public HaarObjectDetector(HaarCascade cascade, int minSize, ObjectDetectorSearchMode searchMode)
     : this(cascade, minSize, searchMode, 1.2f)
 {
 }
Пример #8
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 ///
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.</param>
 /// <param name="minSize">
 ///   Minimum window size to consider when searching for
 ///   objects. Default value is <c>15</c>.</param>
 /// <param name="searchMode">
 ///   The <see cref="ObjectDetectorSearchMode"/> to use
 ///   during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
 ///   for details. Default value is <see cref="ObjectDetectorSearchMode.NoOverlap"/></param>
 /// <param name="scaleFactor">The re-scaling factor to use when re-scaling the window during search.</param>
 ///
 public HaarObjectDetector(HaarCascade cascade, int minSize,
                           ObjectDetectorSearchMode searchMode, float scaleFactor)
     : this(cascade, minSize, searchMode, scaleFactor, ObjectDetectorScalingMode.SmallerToGreater)
 {
 }
Пример #9
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 ///
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.
 /// </param>
 ///
 public HaarObjectDetector(HaarCascade cascade)
     : this(cascade, 15)
 {
 }
Пример #10
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 ///
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.</param>
 /// <param name="minSize">
 ///   Minimum window size to consider when searching for
 ///   objects. Default value is <c>15</c>.</param>
 ///
 public HaarObjectDetector(HaarCascade cascade, int minSize)
     : this(cascade, minSize, ObjectDetectorSearchMode.NoOverlap)
 {
 }
Пример #11
0
 /// <summary>
 ///   Constructs a new classifier.
 /// </summary>
 ///
 public HaarClassifier(HaarCascade cascade)
 {
     this.cascade = cascade;
 }
Пример #12
0
        /// <summary>
        ///   Writes the specified cascade.
        /// </summary>
        /// <param name="cascade">The cascade to write.</param>
        /// <param name="className">The name for the generated class.</param>
        ///
        public void Write(HaarCascade cascade, string className)
        {
            for (int i = 0; i < cascade.Stages.Length; i++)
            {
                for (int j = 0; j < cascade.Stages[i].Trees.Length; j++)
                {
                    if (cascade.Stages[i].Trees[j].Length != 1)
                    {
                        throw new ArgumentException("Only cascades with single node trees are currently supported.");
                    }
                }
            }


            writer.WriteLine("// This file has been automatically transcribed by the");
            writer.WriteLine("//");
            writer.WriteLine("// Accord Vision Library");
            writer.WriteLine("// The Accord.NET Framework");
            writer.WriteLine("// http://accord-framework.net");
            writer.WriteLine("//");
            writer.WriteLine();
            writer.WriteLine("namespace HaarCascades");
            writer.WriteLine("{");
            writer.WriteLine("    using System.CodeDom.Compiler;");
            writer.WriteLine("    using System.Collections.Generic;");
            writer.WriteLine();
            writer.WriteLine("    /// <summary>");
            writer.WriteLine("    ///   Automatically generated haar-cascade definition");
            writer.WriteLine("    ///   to use with the Accord.NET Framework object detectors.");
            writer.WriteLine("    /// </summary>");
            writer.WriteLine("    /// ");
            writer.WriteLine("    [GeneratedCode(\"Accord.NET HaarCascadeWriter\", \"2.7\")]");
            writer.WriteLine("    public class {0} : Accord.Vision.Detection.HaarCascade", className);
            writer.WriteLine("    {");
            writer.WriteLine();
            writer.WriteLine("        /// <summary>");
            writer.WriteLine("        ///   Automatically generated transcription");
            writer.WriteLine("        /// </summary>");
            writer.WriteLine("        public {0}()", className);
            writer.WriteLine("            : base({0}, {1})", cascade.Width, cascade.Height);
            writer.WriteLine("        {");
            writer.WriteLine("            List<HaarCascadeStage> stages = new List<HaarCascadeStage>();");
            writer.WriteLine("            List<HaarFeatureNode[]> nodes;");
            writer.WriteLine("            HaarCascadeStage stage;");
            writer.WriteLine();

            if (cascade.HasTiltedFeatures)
            {
                writer.WriteLine("            HasTiltedFeatures = true;");
                writer.WriteLine();
            }

            // Write cascade stages
            for (int i = 0; i < cascade.Stages.Length; i++)
            {
                writeStage(i, cascade.Stages[i]);
            }

            writer.WriteLine();
            writer.WriteLine("            Stages = stages.ToArray();");
            writer.WriteLine("         }");
            writer.WriteLine("    }");
            writer.WriteLine("}");
        }
Пример #13
0
        /// <summary>
        ///   Constructs a new Haar object detector.
        /// </summary>
        /// <param name="cascade">
        ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
        ///   For the default face cascade, please take a look on
        ///   <see cref="Cascades.FaceHaarCascade"/>.
        /// </param>
        /// <param name="minSize">Minimum window size to consider when searching
        /// objects. Default value is <c>15</c>.</param>
        /// <param name="searchMode">The <see cref="ObjectDetectorSearchMode"/> to use
        /// during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
        /// for details. Default is <see cref="ObjectDetectorSearchMode.NoOverlap"/>.</param>
        /// <param name="scaleFactor">The scaling factor to rescale the window
        /// during search. Default value is <c>1.2f</c>.</param>
        /// <param name="scalingMode">The <see cref="ObjectDetectorScalingMode"/> to use
        /// when re-scaling the search window during search. Default is <see cref="ObjectDetectorScalingMode.SmallerToGreater"/>.</param>
        /// 
        public HaarObjectDetector(HaarCascade cascade, int minSize, ObjectDetectorSearchMode searchMode, float scaleFactor,
            ObjectDetectorScalingMode scalingMode)
        {
            this.classifier = new HaarClassifier(cascade);
            this.minSize = new Size(minSize, minSize);
            this.searchMode = searchMode;
            this.ScalingMode = scalingMode;
            this.factor = scaleFactor;
            this.detectedObjects = new List<Rectangle>();

            this.baseWidth = cascade.Width;
            this.baseHeight = cascade.Height;
        }
Пример #14
0
 /// <summary>
 ///   Constructs a new classifier.
 /// </summary>
 /// 
 public HaarClassifier(HaarCascade cascade)
 {
     this.cascade = cascade;
 }
Пример #15
0
        /// <summary>
        ///   Constructs a new Haar object detector.
        /// </summary>
        /// 
        /// <param name="cascade">
        ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
        ///   For the default face cascade, please take a look on
        ///   <see cref="Cascades.FaceHaarCascade"/>. </param>
        /// <param name="minSize">
        ///   Minimum window size to consider when searching for
        ///   objects. Default value is <c>15</c>.</param>
        /// <param name="searchMode">The <see cref="ObjectDetectorSearchMode"/> to use
        ///   during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
        ///   for details. Default is <see cref="ObjectDetectorSearchMode.NoOverlap"/>.</param>
        /// <param name="scaleFactor">The scaling factor to rescale the window
        ///   during search. Default value is <c>1.2f</c>.</param>
        /// <param name="scalingMode">The <see cref="ObjectDetectorScalingMode"/> to use
        ///   when re-scaling the search window during search. Default is
        ///   <see cref="ObjectDetectorScalingMode.SmallerToGreater"/>.</param>
        /// 
        public HaarObjectDetector(HaarCascade cascade, int minSize,
            ObjectDetectorSearchMode searchMode, float scaleFactor,
            ObjectDetectorScalingMode scalingMode)
        {
            this.classifier = new HaarClassifier(cascade);
            this.minSize = new Size(minSize, minSize);
            this.searchMode = searchMode;
            this.ScalingMode = scalingMode;
            this.factor = scaleFactor;
            this.detectedObjects = new List<Rectangle>();

            this.baseWidth = cascade.Width;
            this.baseHeight = cascade.Height;

            this.match = new GroupMatching(0, 0.2);

#if NET35
            this.parallel = false;
#else
            this.parallel = true;
#endif
        }
Пример #16
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 /// 
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.</param>
 /// <param name="minSize">
 ///   Minimum window size to consider when searching for
 ///   objects. Default value is <c>15</c>.</param>
 /// <param name="searchMode">
 ///   The <see cref="ObjectDetectorSearchMode"/> to use
 ///   during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
 ///   for details. Default value is <see cref="ObjectDetectorSearchMode.NoOverlap"/></param>
 /// <param name="scaleFactor">The re-scaling factor to use when re-scaling the window during search.</param>
 /// 
 public HaarObjectDetector(HaarCascade cascade, int minSize,
     ObjectDetectorSearchMode searchMode, float scaleFactor)
     : this(cascade, minSize, searchMode, scaleFactor, ObjectDetectorScalingMode.SmallerToGreater) { }
Пример #17
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 /// 
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.
 /// </param>
 /// <param name="minSize">
 ///   Minimum window size to consider when searching for
 ///   objects. Default value is <c>15</c>.</param>
 /// <param name="searchMode">The <see cref="ObjectDetectorSearchMode"/> to use
 ///   during search. Please see documentation of <see cref="ObjectDetectorSearchMode"/>
 ///   for details. Default value is <see cref="ObjectDetectorSearchMode.NoOverlap"/></param>
 /// 
 public HaarObjectDetector(HaarCascade cascade, int minSize, ObjectDetectorSearchMode searchMode)
     : this(cascade, minSize, searchMode, 1.2f) { }
Пример #18
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 /// 
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.</param>
 /// <param name="minSize">
 ///   Minimum window size to consider when searching for 
 ///   objects. Default value is <c>15</c>.</param>
 /// 
 public HaarObjectDetector(HaarCascade cascade, int minSize)
     : this(cascade, minSize, ObjectDetectorSearchMode.NoOverlap) { }
Пример #19
0
 /// <summary>
 ///   Constructs a new Haar object detector.
 /// </summary>
 /// 
 /// <param name="cascade">
 ///   The <see cref="HaarCascade"/> to use in the detector's classifier.
 ///   For the default face cascade, please take a look on
 ///   <see cref="Cascades.FaceHaarCascade"/>.
 /// </param>
 /// 
 public HaarObjectDetector(HaarCascade cascade)
     : this(cascade, 15) { }