Emgu.CV中的CudaCascadeClassifier.DetectMultiScale函数有哪些更好的参数?

时间:2019-02-01 05:30:34

标签: c# emgucv

我正在尝试使用C#中的Emgu.CV创建面部识别应用程序。我自己创建了视频流功能,但从https://michaelreeves.us/pages/LaserSystem.html导入了ImageRecognition类。我修改了ImageRecognition代码以删除错误,但是,我不断收到错误:

  

方法'DetectMultiScale'的重载没有4个参数

无论我尝试什么。我应该为该方法使用什么参数?

代码如下:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.Cuda;

namespace VladsEye2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private VideoCapture capture;
        private bool captureInProgress;

        private void ProcessFrame(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> ImageFrame = capture.QueryFrame().ToImage<Bgr, Byte>();
            CamImageBox.Image = ImageFrame;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if(capture == null)
            {
                try
                {
                    capture = new VideoCapture();
                }
                catch(NullReferenceException except)
                {
                    MessageBox.Show(except.Message);
                }
            }

            if (capture != null)
            {
                if (captureInProgress)
                {
                    Application.Idle -= ProcessFrame;
                }
                else
                {
                    Application.Idle += ProcessFrame;
                }

                captureInProgress = !captureInProgress;
            }

            timer1.Start();
        }

        public static class ImageRecognition
        {
            private static List<PointF> facePositions = new List<PointF>();
            public static CudaCascadeClassifier classifier = new CudaCascadeClassifier(@"haarcascade_frontalface_default.xml");

            public static Image<Bgr, byte> detectFace(Image<Bgr, byte> image, out List<PointF> positions)
            {
                Image<Bgr, byte> copyImage = new Image<Bgr, byte>(image.Bitmap);
                facePositions.Clear();

                using (CudaImage<Bgr, Byte> gpuImage = new CudaImage<Bgr, byte>(image))
                using (CudaImage<Gray, Byte> gpuGray = gpuImage.Convert<Gray, Byte>())
                {
                    foreach (Rectangle face in (IEnumerable<Rectangle>)classifier.DetectMultiScale(gpuGray, 1.2, 10, Size.Empty))
                    {
                        copyImage.Draw(face, new Bgr(Color.Red), 4);
                        facePositions.Add(new PointF(face.Location.X + (face.Width / 2), face.Location.Y + (face.Height / 2)));
                    }
                    positions = facePositions;
                }
                return copyImage;
            }
        }
    }
}

0 个答案:

没有答案