出现错误:“ Image <灰色,字节>”不包含“ DetectHaarCascade”的定义,并且没有可访问的扩展方法“ DetectHaarCascade”

时间:2019-09-22 13:33:46

标签: c# python opencv emgucv face-detection

我正在使用C#中的EmguCV进行人脸检测项目,我的目标是从网络摄像头中检测人脸。同时,我遇到了一些错误。

我包括了所有EmguCV依赖项和OpenCV依赖项。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;

namespace demo
{
    public partial class Form1 : Form
    {
        private VideoCapture cap;
        private CascadeClassifier haar;
        public Form1()
        {
            InitializeComponent();
        }

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

        private void timer1_Tick(object sender, EventArgs e)
        {
            using (Image<Bgr, byte> nextFrame = cap.QueryFrame().ToImage<Bgr, Byte>())
            {
                if (nextFrame != null)
                {
                    // there's only one channel (greyscale), hence the zero index
                    //var faces = nextFrame.DetectHaarCascade(haar)[0];
                    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);
                    }
                    pictureBox1.Image = nextFrame.ToBitmap();
                }
            }
        }
    }
}

我尝试将DetectHaarcascade替换为Detectmultiscale

  

ErrorCS1061:“图像”不包含“ DetectHaarCascade”的定义,找不到可以接受的扩展方法“ DetectHaarCascade”接受类型为“图像”的第一个参数(您是否缺少using指令或程序集引用?)

     

ErrorCS0103:名称“ HAAR_DETECTION_TYPE”在当前上下文中不存在

     

ErrorCS1579:foreach语句无法对类型为'?'的变量进行操作因为“?”不包含“ GetEnumerator”的公共实例定义

1 个答案:

答案 0 :(得分:0)

尝试添加以下库文件:

bullet.GetComponent<Rigidbody2D>().velocity = direction * speed