DetectMultiScale() public method

Performs object detection with a multi-scale window.
public DetectMultiScale ( OpenCvSharp.Mat img, double hitThreshold, Size winStride = null, Size padding = null, double scale = 1.05, int groupThreshold = 2 ) : Rect[]
img OpenCvSharp.Mat Source image. CV_8UC1 and CV_8UC4 types are supported for now.
hitThreshold double Threshold for the distance between features and SVM classifying plane.
winStride Size Window stride. It must be a multiple of block stride.
padding Size Mock parameter to keep the CPU interface compatibility. It must be (0,0).
scale double Coefficient of the detection window increase.
groupThreshold int Coefficient to regulate the similarity threshold. /// When detected, some objects can be covered by many rectangles. 0 means not to perform grouping.
return Rect[]
コード例 #1
0
ファイル: HOGSample.cs プロジェクト: CodeSang/opencvsharp
        public void Run()
        {
            var img = Cv2.ImRead(FilePath.Image.Asahiyama, ImreadModes.Color);

            var hog = new HOGDescriptor();
            hog.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());

            bool b = hog.CheckDetectorSize();
            Console.WriteLine("CheckDetectorSize: {0}", b);

            var watch = Stopwatch.StartNew();

            // run the detector with default parameters. to get a higher hit-rate
            // (and more false alarms, respectively), decrease the hitThreshold and
            // groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
            Rect[] found = hog.DetectMultiScale(img, 0, new Size(8, 8), new Size(24, 16), 1.05, 2);

            watch.Stop();
            Console.WriteLine("Detection time = {0}ms", watch.ElapsedMilliseconds);
            Console.WriteLine("{0} region(s) found", found.Length);

            foreach (Rect rect in found)
            {
                // the HOG detector returns slightly larger rectangles than the real objects.
                // so we slightly shrink the rectangles to get a nicer output.
                var r = new Rect
                {
                    X = rect.X + (int)Math.Round(rect.Width * 0.1),
                    Y = rect.Y + (int)Math.Round(rect.Height * 0.1),
                    Width = (int)Math.Round(rect.Width * 0.8),
                    Height = (int)Math.Round(rect.Height * 0.8)
                };
                img.Rectangle(r.TopLeft, r.BottomRight, Scalar.Red, 3);
            }

            using (var window = new Window("people detector", WindowMode.Normal, img))
            {
                window.SetProperty(WindowProperty.Fullscreen, 1);
                Cv2.WaitKey(0);
            }
        }