0

全部,

我刚刚在最新版本的 Emgu CV 中尝试了人脸检测示例,我的程序运行良好,但我无法从图像或网络摄像头实时捕获中获取任何人脸。

我的操作系统是 Windows 8 Enterprise x64。我的IDE是VS2012。

顺便说一句,我也试过 HaarCascade 和 CascadeClassifier。他们都无法得到结果。返回变量的值将始终为 {Emgu.CV.Structure.MCvAvgComp[0]}

cap = new Capture(0);
// adjust path to find your xml
//ccf = new CascadeClassifier("D:\\haarcascade_frontalface_alt_tree.xml");
haar = new HaarCascade("D:\\haarcascade_frontalface_alt_tree.xml");
Image inputImg = Image.FromFile(@"D:\1.jpg");

Image<Bgr, byte> imageFrame = new Image<Bgr, byte>(new Bitmap(inputImg));

if (imageFrame != null) {
    Image<Gray, byte> grayFrame = imageFrame.Convert<Gray, byte>();

var faces = grayFrame.DetectHaarCascade(haar, 1.1, 10, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20))[0];

foreach (var face in faces) {
                imageFrame.Draw(face.rect, new Bgr(Color.Green), 3);
            }
}
pictureBox1.Image = imageFrame.ToBitmap();

有什么想法或帮助吗?非常感谢。

解决了谢谢。

4

1 回答 1

0

我已经使用 Haar cascaades 方法对检测到的行人做了一个类似的程序,看看下面的代码是否有帮助:

private void Haar(object sender, EventArgs arg)
        {

            Image<Bgr, Byte> frame;
            Image<Gray, Byte> Gray_frame;

            HaarCascade UpperBody = new HaarCascade("haarcascade_mcs_upperbody.xml");
            HaarCascade LowerBody = new HaarCascade("haarcascade_lowerbody.xml");
            HaarCascade FullBody = new HaarCascade("haarcascade_lowerbody.xml");

            try
            {
                frame = _capture.QueryFrame();

                Gray_frame = frame.Convert<Gray, byte>();

                double fps = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);
                //Gray_frame = foreground(frame);

                if (inteiro == false)
                {

                    MCvAvgComp[] cima = UpperBody.Detect(Gray_frame, escala, vizinhos,
                        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                        new System.Drawing.Size(size1, size2));

                    MCvAvgComp[] baixo = LowerBody.Detect(Gray_frame, escala, vizinhos,
                        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                        new System.Drawing.Size(size1, size2));


                    foreach (MCvAvgComp body in cima)
                    {
                        Gray_frame.Draw(body.rect, new Emgu.CV.Structure.Gray(10), 2);
                        cout++;
                    }
                    foreach (MCvAvgComp body in baixo)
                    {
                        Gray_frame.Draw(body.rect, new Emgu.CV.Structure.Gray(10), 2);
                        cout++;
                    }
                }

                //Full Body

                if (inteiro == true)
                {

                    MCvAvgComp[] full = FullBody.Detect(Gray_frame, escala, vizinhos,
                        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                        new System.Drawing.Size(size1, size2));


                    foreach (MCvAvgComp body in full)
                    {

                        Gray_frame.Draw(body.rect, new Emgu.CV.Structure.Gray(10), 2);
                        cout++;
                    }
                }

                this.Text = cout.ToString();
                imageBox1.Image = Gray_frame;
            }
            catch { }
        }
于 2013-07-16T14:04:53.297 回答