1
因此,我正在開發一個小應用程序來識別臉部,因爲人們走進我的房間以便向他們大喊大叫(成熟,我知道)。OpenCV人臉識別:索引超出範圍更新Emgu.CV.UI.ImageBox.Image
問題是,我有面部識別識別面孔,但將其繪製到屏幕上是有問題的。嚴格地說,它不需要在屏幕上畫任何東西,但我只是想看看它的工作。
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包裝器。