Example #1
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
        }
Example #2
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("// BestCS Vision Library");
            writer.WriteLine("// The BestCS.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 BestCS.NET Framework object detectors.");
            writer.WriteLine("    /// </summary>");
            writer.WriteLine("    /// ");
            writer.WriteLine("    [GeneratedCode(\"BestCS.NET HaarCascadeWriter\", \"2.7\")]");
            writer.WriteLine("    public class {0} : BestCS.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("}");
        }
Example #3
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)
 {
 }
Example #4
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)
 {
 }
Example #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>
 ///
 public HaarObjectDetector(HaarCascade cascade, int minSize)
     : this(cascade, minSize, ObjectDetectorSearchMode.NoOverlap)
 {
 }
Example #6
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)
 {
 }
Example #7
0
 /// <summary>
 ///   Constructs a new classifier.
 /// </summary>
 ///
 public HaarClassifier(HaarCascade cascade)
 {
     this.cascade = cascade;
 }