【问题标题】:'Emgu.CV.Util.CvException' occurred in 'Emgu.CV.World.dll' - When trying to Predict“Emgu.CV.Util.CvException”发生在“Emgu.CV.World.dll”中 - 尝试预测时
【发布时间】: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


【解决方案1】:

好的,我找到了解决方案。问题不在于我的代码。当本机代码尝试访问某些已损坏或无法访问的内存位置时,会引发此错误。
所以我找到了一个简单有效的解决方案。

try
{
   var result = recognizer.Predict(image);
}
catch (System.AccessViolationException)
{
   recognier =  new EigenFaceRecognizer(80, double.PositiveInfinity);
}

但您无法在运行时捕获 AccessViolationException。因此,您必须更改设置才能做到。为此,您可以关注this question 和答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-26
    • 2010-11-04
    • 2019-11-01
    • 1970-01-01
    • 2013-12-21
    • 2019-07-10
    • 1970-01-01
    • 2018-01-21
    相关资源
    最近更新 更多