使用C#进行Emgu CV图像捕获

时间:2017-07-19 00:44:24

标签: c# emgucv face-detection face-recognition

我使用的是Emgu CV 2.4.0.1717,每当我声明Mat类时它都不存在。我正在尝试使用可以捕获图像的c#创建应用程序。这是我的面部识别项目。

我试图声明一个Mat对象,但它不存在。我尝试过使用其他版本的Emgu CV,但它确实有效。但是,HaarCascade并不存在。它声明我应该使用CascadeClassifier,但仍然存在错误。这是我的代码:

public partial class Camera : Form
{

    private VideoCapture cap;
    private HaarCascade haar;

    private void Camera_Load(object sender, EventArgs e)
    {
        // passing 0 gets zeroth webcam
        cap = new VideoCapture(0);
        // adjust path to find your xml
        haar = new HaarCascade(
        "haarcascade_frontalface_default.xml");
    } 

    private void timer1_Tick(object sender, EventArgs e)
    {
        using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
        {
            if (nextFrame != null)
            {

                Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
                var faces =
                    grayframe.DetectHaarCascade(
                        haar, 1.4, 4,
                        HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                        new Size(nextFrame.Width / 8, nextFrame.Height / 8)
                        )[0];

                foreach (var face in faces)
                {
                    nextFrame.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 3);
                }
                imgCamUser.Image = nextFrame.ToBitmap();
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您尝试访问的Mat类来自emgucv 3+。而HaarCascade类是emgu的较低版本。

您需要从here将emgu升级到emgu 3并使用CascadeClassifier而不是HaarCascade。

相关问题