C# 获取错误:';图像<;灰色,字节>';不包含';检测ARCASCADE';没有可访问的扩展方法';检测ARCASCADE';

C# 获取错误:';图像<;灰色,字节>';不包含';检测ARCASCADE';没有可访问的扩展方法';检测ARCASCADE';,c#,python,opencv,emgucv,face-detection,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 Syst

我正在做一个关于在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();
                }
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用Emgu.CV;
使用Emgu.Util;
使用Emgu.CV.Structure;
使用Emgu.CV.CvEnum;
名称空间演示
{
公共部分类Form1:Form
{
私人视频捕捉帽;
哈尔私人酒店;
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
//通过0将获得第0个网络摄像头
cap=新视频捕获(0);
//调整路径以查找xml
haar=新的级联分类器(“haarcascade_frontalface_alt2.xml”);
}
私有无效计时器1_刻度(对象发送方,事件参数e)
{
使用(Image nextFrame=cap.QueryFrame().ToImage())
{
if(nextFrame!=null)
{
//只有一个通道(灰度),因此索引为零
//var faces=nextFrame.DetectHaarCascade(haar)[0];
Image grayframe=nextFrame.Convert();
变量面=
grayframe.DetectHarcascade(haar,1.4,4,haar_DETECTION_TYPE.DO_CANNY_修剪,新尺寸(nextFrame.Width/8,nextFrame.Height/8))[0];
foreach(面中的面变量)
{
nextFrame.Draw(face.rect,新Bgr(0,double.MaxValue,0),3);
}
pictureBox1.Image=nextFrame.ToBitmap();
}
}
}
}
}
我尝试用
Detectmultiscale
替换
detectHarcascade

ErrorCS1061:“Image”不包含“DetectShareCascade”的定义,并且找不到可访问的扩展方法“DetectShareCascade”,该扩展方法接受类型为“Image”的第一个参数(是否缺少using指令或程序集引用?)

ErrorCS0103:名称“HAAR\u检测类型”在当前上下文中不存在

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


尝试添加以下库:

using Emgu.CV.UI;
using System.Drawing;
using System.Diagnostics;

可能需要检查您的Emgu.CV版本。文档似乎表明,对于
detectharcascade
您至少需要2.4.2.1777,实际上我使用的是最新版本的Emgu