【问题标题】:Getting error:'Image<Gray, byte>' does not contain a definition for 'DetectHaarCascade' and no accessible extension method 'DetectHaarCascade'出现错误:“Image<Gray, byte>”不包含“DetectHaarCascade”的定义,并且没有可访问的扩展方法“DetectHaarCascade”
【发布时间】:2020-01-22 18:32:09
【问题描述】:

我正在做一个在 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:“Image”不包含“DetectHaarCascade”的定义,并且找不到接受“Image”类型的第一个参数的可访问扩展方法“DetectHaarCascade”(您是否缺少 using 指令或程序集引用?)

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

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

【问题讨论】:

标签: c# python opencv emgucv face-detection


【解决方案1】:

尝试添加这些库:

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

【讨论】:

    猜你喜欢
    • 2020-06-14
    • 2023-01-19
    • 2022-07-21
    • 2023-01-12
    • 2020-10-06
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多