OpenCV 4.7 C++17 Windows 10 - imread warn cutoff, empty return

When attempting to open a jpg or png with imread, I always get the same WARN, and then it fails to load the image.

The error is cutoff compared to all the other errors I see when I search (I got an error about imwrite command help for example).

It goes:
[ WARN 0@0.840] global loadsave.cpp:244 cv::findDecoder imread_('
…with no filename at all.

I explicitly check that the file exists with the C++17 std::filesystem::exists() func, with the file path (roughly) declared as:
const String image_path = String("C:/Users/user/repository/image.jpg")'

Then, I just call it like:
Mat image = imread(image_path, IMREAD_UNCHANGED);
It then returns an empty Mat object.

What may be causing this error?

please try to debug this …

It could be caused by a faulty image file, perhaps an empty file, where the file format signature is not recognized by the recognizers (see the code).

this is ‘idealized’ (so no problem)

please show real world data / filenames, that make this happen !

I found an image on Google that I can share for this test (from https://ecdn.teacherspayteachers.com/thumbitem/2D-Shapes-Poster-4602583-1559330790/original-4602583-1.jpg).

I renamed the file to shapes-color.jpg, reflected that in the code, and get the same error.

I took a look at that code, and it is part of what confuses me. Why would the warning log prematurely end while trying to read in my filename?

I am attempting to get Visual Studio to comply and let me set a breakpoint in or step into imread, but I am not having any luck.

you need a DEBUG build of the opencv libs for that.

this is indeed the most interesting question here !

is there any chance, you made a mess in your VS project ?
opencv actually only requires c++11. what happens, if you restrict it to that (instead of c++17) ?

It is especially bizarre…

I even just now attempted to emulate the source code exactly by doing:

FILE* f = fopen(filename.c_str(), "rb");
if (f) {
    cout << "Opened file just fine!" << endl;
}

This opened a handle to the file just fine.

Reverting my Visual Studio 2022 to C++14 still has the same error…and I’m not a fan of the idea of trying to install an old Visual Studio to test C++11.

understood …

btw, i don’t think, it’s anything about the image data (code does not get that far …)

that at least means, your compiler isn’t broken :wink:
however, something horrible seems to happen to same code deep inside imgcodecs .

There is not like some separate image processing libraries I need to install that are not present in the 4.7 installer on the website, is there?

I installed only this (https://github.com/opencv/opencv/releases/download/4.7.0/opencv-4.7.0-windows.exe) and cmake.

I setup Visual Studio following this tutorial as closely as I could: How to install OpenCV for C in Windows.