简体   繁体   中英

Nullreference Exception while loading an image using emgucv?

I am trying to load set of images for training using KNN algorithm.Every time , when i try to load the image,NullReferenceException occurs. I use OpenCV and EmguCV (.net Wrapper).I have attached the source code of the project with image dataset. The training folder contains the images. link to project: http://goo.gl/z5dVLX what should i do to make it work?

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);
            }

            // ...
        }
    }
}

I get the following exception:

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

cvlibcs.dll ? Which version of EmguCV do you try to use ? There are no cvlibcs.dll in EmguCV...

You should go on Emgu website and follow some tutorials, reding an image with Emgu is more like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM