我想加载一组使用KNN算法的训练图像。每当我尝试加载图像时,都会发生NullReferenceException。 我使用OpenCV和EmguCV(.net Wrapper)。我已经附加了图像数据集的项目源代码。 训练文件夹包含图像。 链接到项目:http://goo.gl/z5dVLX 我该怎么做才能使它工作?使用emgucv加载图像时的Null引用异常?
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条目]中有相当多的部分(http://file.emgu.com/wiki/index.php/Download_And_Installation#The_type_initializer_for_.27Emgu.CV.CvInvoke.27_threw_an_exception。) –
@DasKrümelmonster该库似乎是工作正常。当我运行该项目时,它有以下错误:在cvlibcs.dll中发生类型'System.NullReferenceException'的第一次机会异常 在cvlibcs.dll中发生未处理的异常'System.NullReferenceException' 其他信息: 你调用的对象是空的。' .. \ .. \ Training \ .. \ .. \ Training \ 0 \ 000.pbm' – user3375375
“似乎工作正常” - 相反。你会得到一个异常,我会说这不是“好”的。你有没有试过链接中的所有内容?你的程序是x86还是x64? –