Emgu.CV.CascadeClassifier.DetectMultiScale C# (CSharp) Метод

DetectMultiScale() публичный Метод

Finds rectangular regions in the given image that are likely to contain objects the cascade has been trained for and returns those regions as a sequence of rectangles. The function scans the image several times at different scales. Each time it considers overlapping regions in the image. It may also apply some heuristics to reduce number of analyzed regions, such as Canny prunning. After it has proceeded and collected the candidate rectangles (regions that passed the classifier cascade), it groups them and returns a sequence of average rectangles for each large enough group.
public DetectMultiScale ( Byte>.Image image, double scaleFactor, int minNeighbors, Size minSize, Size maxSize ) : System.Drawing.Rectangle[]
image Byte>.Image The image where the objects are to be detected from
scaleFactor double The factor by which the search window is scaled between the subsequent scans, for example, 1.1 means increasing window by 10%
minNeighbors int Minimum number (minus 1) of neighbor rectangles that makes up an object. All the groups of a smaller number of rectangles than min_neighbors-1 are rejected. If min_neighbors is 0, the function does not any grouping at all and returns all the detected candidate rectangles, which may be useful if the user wants to apply a customized grouping procedure
minSize System.Drawing.Size Minimum window size. Use Size.Empty for default, where it is set to the size of samples the classifier has been trained on (~20x20 for face detection)
maxSize System.Drawing.Size Maxumum window size. Use Size.Empty for default, where the parameter will be ignored.
Результат System.Drawing.Rectangle[]
        public Rectangle[] DetectMultiScale(Image<Gray, Byte> image, double scaleFactor, int minNeighbors, Size minSize, Size maxSize)
        {
            using (MemStorage stor = new MemStorage())
             {
            Seq<Rectangle> rectangles = new Seq<Rectangle>(stor);

            CvInvoke.CvCascadeClassifierDetectMultiScale(_ptr, image, rectangles, scaleFactor, minNeighbors, 0, minSize, maxSize);
            return rectangles.ToArray();
             }
        }

Usage Example

Пример #1
1
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


        //::::::::::::Detection of the hand in a gray image::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        public List<Object> Detection(Image<Gray, Byte> frame)
        {   
            List<Object> listReturn = new List<object>(2);
            haar = new CascadeClassifier(@"C:\Users\America\Documents\MySystemV1\classifier\cascade.xml");
            

            if (frame != null)
            {
                System.Drawing.Rectangle[] hands = haar.DetectMultiScale(frame, 1.1, 4, new System.Drawing.Size(frame.Width / 8, frame.Height / 8), new System.Drawing.Size(frame.Width / 3, frame.Height / 3));

                foreach (System.Drawing.Rectangle roi in hands)
                {
                    roi.Inflate(-5, 17);                 // Make the roi bigger, becuse we dont obteined the tootal length of the fingers, in some cases. 
                    frame.Draw(roi, new Gray (255), 3);
                }

                if (hands.Count() == 0)
                { 
                    Rectangle[] noDetection= new Rectangle[]{}; 
                    //noDetection[0] = Rectangle.Empty;
                    listReturn.Add(noDetection); 
                }
                else
                {
                    listReturn.Add(hands);
                }
                
            }

            listReturn.Add(frame);

            return listReturn;
            //Regresa los dos valores si el frame es diferente de null, lo cual se supone que siempre es cierto, por que eso se toma en cuenta desde data poll
        }//finaliza detection()   
All Usage Examples Of Emgu.CV.CascadeClassifier::DetectMultiScale