【发布时间】: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?