Search code examples
c++opencvdirectoryimread

cv::imread() in OpenCV not reading my .png


I am really new to OpenCV and I was wondering why my debug string for empty matrix is running when I check if I have a png in my directory. I can confirm that I do indeed have an image by given name in the specified directory.

relevant code:

    cv::Mat imgTrainingNumbers;
    imgTrainingNumbers = cv::imread("C:/Users/.../source/repos/AutoTrader/training_chars2.png");
    if (imgTrainingNumbers.empty()) {                               // if unable to open image
        std::cout << "error: image not read from file\n\n";         // show error message on command line
        return(0);                                                  // and exit program
    }

directory: enter image description here

enter image description here

the program does run up until it tries to open an image. I am confused, why does it do this and what am I doing wrong?


Solution

  • It is possible that the image you are using is of corrupted data. The imread() function will not return anything to your imgTrainingNumbers matrix if you... a. have not specified the path correctly b. the image is not in a proper format/is corrupted c. some linking issue

    Replace the image with something else to test the theory.