【问题标题】:Nullreference Exception while loading an image using emgucv?使用 emgucv 加载图像时出现空引用异常?
【发布时间】:2014-03-11 16:08:25
【问题描述】:

我正在尝试使用 KNN 算法加载一组图像进行训练。每次,当我尝试加载图像时,都会发生 NullReferenceException。 我使用 OpenCV 和 EmguCV(.net Wrapper)。我已将项目的源代码附加到图像数据集。 训练文件夹包含图像。 项目链接:http://goo.gl/z5dVLX 我应该怎么做才能让它工作?

public void getData()
{
    CvMat row = new CvMat();
    CvMat data = new CvMat();
    string file;
    int i = 7, j = 0;
    for (i = 0; i < classes; i++)
    {
        for (j = 0; j < train_samples; j++)
        {
            if (j < 10)
                file = file_path + i.ToString() + "\\" + i.ToString() + "0" + j.ToString() + ".pbm";
            else
                file = file_path + i.ToString() + "\\" + i.ToString() + j.ToString() + ".pbm";

            form.WriteLine("Training..." + file,true,true);

            // Exception occurs here
            src_image = highgui.CvLoadImage(file, highgui.CV_LOAD_IMAGE_GRAYSCALE);

            if (src_image.ptr == null)
            {
                form.WriteLine("Error: Cant load image: " + file + "\n", true, true);
            }

            // ...
        }
    }
}

我得到以下异常:

未处理的类型异常 'System.NullReferenceException' 发生在 cvlibcs​​.dll 中

附加 信息:对象引用未设置为对象的实例。 ....\Training\ ....\Training\0\000.pbm

【问题讨论】:

  • 你试过什么? wiki entry 中有相当广泛的部分
  • @DasKrümelmonster 该库似乎工作正常。当我运行该项目时,它有以下错误A first chance exception of type 'System.NullReferenceException' occurred in cvlibcs.dll An unhandled exception of type 'System.NullReferenceException' occurred in cvlibcs.dll Additional information: Object reference not set to an instance of an object.' ..\..\Training\ ..\..\Training\0\000.pbm
  • “似乎工作正常” - 相反。你得到一个例外,我会说这不是“好”。您是否尝试过链接中的所有内容?你的程序是 x86 还是 x64?

标签: c# .net opencv emgucv knn


【解决方案1】:

cvlibcs​​.dll ?您尝试使用哪个版本的 EmguCV? EmguCV中没有cvlibcs​​.dll...

你应该去 Emgu 网站并按照一些教程进行操作,使用 Emgu 编辑图像更像是这样的:

Image<Bgr, Byte> img1 = new Image<Bgr, Byte>("MyImage.jpg");

【讨论】:

  • 我正在尝试编译项目,使用旧版本的 Emgucv,我已经尝试了多次。您可以帮助我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多