【发布时间】:2017-01-13 10:05:42
【问题描述】:
我正在使用 EmguCV 3.1 开发人脸识别应用程序。我使用 EigenFaceRecognizer 作为识别算法。我尝试使用下面的代码训练图像。
List<Image<Gray, byte>> trainingImages = new List<Image<Gray, byte>>();
FaceRecognizer recognizer;
List<Face> faceList = new List<Face>();
...
...
recognizer = new EigenFaceRecognizer(80, double.PositiveInfinity);
...
...
Image<Gray, byte> image = new Image<Gray, byte>(imgBox2.DisplayedImage.Bitmap);
trainingImages.Add(image);
List<int> trainigLabels = new List<int>();
recognizer.Train(trainingImages.ToArray(), trainigLabels.ToArray());
recognizer.Save("TraningData");
faceList.Add(new Face(image.Bytes.Length, txtName.Text));
...
...
Image<Gray, byte> image = new Image<Gray, byte>(imgBox2.DisplayedImage.Bitmap);
recognizer.Load("TraningData");
try
{
var result = recognizer.Predict(image);
MessageBox.Show(result.Label.ToString());
}
catch (Emgu.CV.Util.CvException ex)
{
Console.WriteLine(ex);
}
但是当调用此代码时,它会给我以下错误。
A first chance exception of type 'Emgu.CV.Util.CvException' occurred in Emgu.CV.World.dll
The program '[1136] IPTest.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
The program '[1136] IPTest.vshost.exe: Program Trace' has exited with code 0 (0x0).
在尝试使用 recognizer.Train() 时发生。我做错了什么?
更新
经过反复试验,我知道问题出在识别器.Predict() 方法上。
当我使用 try/catch 时,它显示以下异常
Emgu.CV.Util.CvException: OpenCV: The matrix is not continuous, thus its number of rows can not be changed
【问题讨论】:
-
如果我没记错的话,
first chance exception表示您在某处捕获了异常,否则在您的代码周围放置一个try/catch块并捕获它。请向我们显示异常消息和堆栈跟踪 -
@slawekwin 谢谢。我会更新问题
-
recognizer.Train()或recognizer.Predict()中的错误也是?
标签: c# opencv emgucv face-detection face-recognition