Exemplo n.º 1
0
        private void Detect(Bitmap image,ObjectDetectorSearchMode searchMode, int supperession,ObjectDetectorScalingMode scalingMode,string targetPath,bool parallelProcessing)
        {
            //http://www.codeproject.com/Tips/561129/Face-Detection-with-Lines-of-Code-VB-NET

            //describing Viola Jones here : http://makematics.com/research/viola-jones/

            //choosing scaling factor : http://www.mathworks.com/help/vision/ref/vision.cascadeobjectdetector-class.html#btc108o

            var detector = new HaarObjectDetector(new FaceHaarCascade(), 30);
            detector.SearchMode = searchMode;
            if (searchMode == ObjectDetectorSearchMode.Average)
                detector.Suppression = supperession;
            detector.MaxSize = new Size(image.Width, image.Height);
            detector.ScalingMode = scalingMode;
            detector.UseParallelProcessing = parallelProcessing;

            int scalingValue = image.Width > image.Height ? image.Width : image.Height;
            detector.ScalingFactor = scalingValue / (scalingValue - 0.5f);

            Rectangle[] faceObjects = detector.ProcessFrame(image);
            var p = new Pen(Color.Aqua, 10);

            var graphicRect = Graphics.FromImage(image);

            foreach (var face in faceObjects)
            {
                graphicRect.DrawRectangle(p, face);
            }
            graphicRect.Dispose();
            image.Save(targetPath);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            watch.Stop();

            #region extracting icon from application to this form window
            Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            #endregion

            #region Load default Mask Image
            if (File.Exists("mask.png"))
            {
                mask = LoadMask("mask.png");
            }
            else
            {
                mask = Icon.ToBitmap();
            }
            erase = new Bitmap(mask.Width, mask.Height, PixelFormat.Format32bppArgb);
            #endregion

            #region Add file(s) from command line args
            string[] flist = Environment.GetCommandLineArgs();
            lvFiles.Items.Clear();
            foreach (string f in flist)
            {
                if (PhotoExts.Contains(Path.GetExtension(f), StringComparer.CurrentCultureIgnoreCase))
                {
                    if (lvFiles.Items.Count == 0 || lvFiles.FindItemWithText(f, true, 0) == null)
                    {
                        ListViewItem fItem = new ListViewItem(new string[] { Path.GetFileName(f), f });
                        lvFiles.Items.Add(fItem);
                    }
                }
            }
            #endregion

            picPreview.SizeMode = PictureBoxSizeMode.Zoom;
            picPreview.Image    = photo;

            picMask.SizeMode = PictureBoxSizeMode.Zoom;
            picMask.Image    = mask;

            cbMode.DataSource    = Enum.GetValues(typeof(ObjectDetectorSearchMode));
            cbScaling.DataSource = Enum.GetValues(typeof(ObjectDetectorScalingMode));

            cbMode.SelectedItem    = ObjectDetectorSearchMode.NoOverlap;
            cbScaling.SelectedItem = ObjectDetectorScalingMode.SmallerToGreater;

            SearchMode  = ObjectDetectorSearchMode.NoOverlap;
            ScalingMode = ObjectDetectorScalingMode.SmallerToGreater;

            OutSize  = (int)numOutSize.Value;
            faceSize = (int)numFaceSize.Value;

            GrayFirst = chkGrayDetect.Checked;

            HaarCascade cascade = new FaceHaarCascade();
            detector = new HaarObjectDetector(cascade);
        }
Exemplo n.º 3
0
 private FaceDetectorParameters(float scalingFactor, int minimumSize, ObjectDetectorScalingMode objectDetectorScalingMode,
                                ObjectDetectorSearchMode objectDetectorSearchMode, bool useParallelProcessing, int suppression, bool isValid)
 {
     ScalingFactor         = scalingFactor;
     MinimumSize           = minimumSize;
     ScalingMode           = objectDetectorScalingMode;
     SearchMode            = objectDetectorSearchMode;
     UseParallelProcessing = useParallelProcessing;
     Suppression           = suppression;
     IsValid = isValid;
 }
Exemplo n.º 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
        /// 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;
        }
        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;
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Constructs a new Haar object detector.
        /// </summary>
        ///
        /// <param name="cascade">
        ///   The <see cref="Lenneth.Core.Framework.ImageProcessor.Imaging.Filters.ObjectDetection.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.HaarCascade cascade, int minSize,
                                  ObjectDetectorSearchMode searchMode, float scaleFactor,
                                  ObjectDetectorScalingMode scalingMode)
        {
            _classifier      = new HaarClassifier(cascade);
            this._minSize    = new Size(minSize, minSize);
            this._searchMode = searchMode;
            ScalingMode      = scalingMode;
            _factor          = scaleFactor;
            _detectedObjects = new List <Rectangle>();

            _baseWidth  = cascade.Width;
            _baseHeight = cascade.Height;

            _match = new RectangleGroupMatching(0, 0.2);
        }
Exemplo n.º 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 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
        }
Exemplo n.º 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 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
        }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cbScaling_SelectionChangeCommitted(object sender, EventArgs e)
 {
     ScalingMode = (ObjectDetectorScalingMode)cbScaling.SelectedValue;
 }
Exemplo n.º 10
0
 public static FaceDetectorParameters Create(float scalingFactor, int minimumSize, ObjectDetectorScalingMode objectDetectorScalingMode,
                                             ObjectDetectorSearchMode objectDetectorSearchMode, bool useParallelProcessing, int suppression) =>
 new FaceDetectorParameters(scalingFactor, minimumSize, objectDetectorScalingMode, objectDetectorSearchMode, useParallelProcessing, suppression, true);