【发布时间】: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”的公共实例定义
【问题讨论】:
-
可能想要检查您拥有的 Emgu.CV 的版本。文档似乎表明,对于
DetectHaarCascade,您至少需要 2.4.2.1777 emgu.com/wiki/files/2.4.2/document/html/… -
其实我用的是最新版的Emgu
标签: c# python opencv emgucv face-detection