【发布时间】:2016-05-23 13:37:34
【问题描述】:
所以我正在开发一个小应用程序来识别人们走进我房间时的面孔,以便对他们大喊大叫(成熟,我知道)。
问题是,我有面部识别识别面部,但将其绘制到屏幕上是有问题的。严格来说,它不需要在屏幕上绘制任何东西,但我只想看到它工作。
Form1.cs
using System;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using System.Threading;
using System.Drawing;
namespace OpenCVApp1 {
public partial class Form1 : Form {
ImageViewer viewer = new ImageViewer(); //create an image viewer
private Capture cap = new Capture(0);
private CascadeClassifier cascade = new CascadeClassifier("..\\..\\Resources\\haarcascade_frontalface_alt2.xml");
Thread camWorker;
public Form1() {
InitializeComponent();
Application.ApplicationExit += Application_ApplicationExit;
cap = new Capture(0);
camWorker = new Thread(() => {
while (true) {
Image<Bgr, byte> frame = cap.QueryFrame().ToImage<Bgr, byte>();
Image<Gray, byte> grayFrame = frame.Convert<Gray, byte>();
Rectangle[] faces = cascade.DetectMultiScale(grayFrame, 1.1, 10);
foreach (Rectangle face in faces) {
frame.Draw(face, new Bgr(Color.Red), 2);
}
imgCamUser.Image = frame;
Thread.Sleep(100);
}
});
camWorker.Start();
}
private void Application_ApplicationExit(object sender, EventArgs e) {
camWorker.Abort();
}
}
}
它适用于几帧,正确地在面部周围绘制一个框,然后抛出一个:
An unhandled exception of type 'Emgu.CV.Util.CvException' occurred in System.Windows.Forms.dll
Additional information: OpenCV: index is out of range
就是这样。我使用 OpenCV 3.10 和 Emgu 作为 .NET 包装器。
【问题讨论】: