Image Not Loading In OpenCV 4.x.x
[ UPDATE ]
This issue is still unresolved. I have also asked it in the Stack Overflow (here) but failed to get any solution. Thus, I have uploaded videos to explain the problem. So, Kindly take a look for clarification.
I am not sure if I am the only one facing this issue. But In my machine, images are not loading in OpenCV 4.x.x. I have tried 4.0.0 (prebuilt x64 Windows binaries), 4.1.1(prebuilt x64 Windows binaries) and 4.1.2(built x64 binaries from source using VS 2019).
Interestingly, the same code works for OpenCV 3.x.x.
Am I missing something?
#include <iostream>
#include <filesystem>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
Mat image;
string imagePath = filesystem::current_path().string() + "\\images\\road.jpg";
cout << "Image Path : " << imagePath << "\n";
image = imread(imagePath, IMREAD_COLOR);
if (image.empty())
{
cout << "ERROR READING IMAGE!";
return -1;
}
String windowTitle = "Hello OpenCV";
namedWindow(windowTitle, WINDOW_AUTOSIZE);
imshow(windowTitle, image);
waitKey(0);
return 0;
}
Development Environment
- Windows 10 64 Bit
- Visual Studio 2019 Community Edition
May be image is empty! You can try
Can you read image? If yes path or file problem . If no ...
I'm sure you have googled and found problems where imread fails if the program and opencv library do not have matching build type - release or debug, so I'd check that
@LBerger, Yes, the image created by the above code can be read by imread(). But I do not think there is any path or file related problem. That exact same code works with OpenCV 3.x.x.
@mvuori, I think there is no mismatch. The program runs fine except for the fact that for some reason, imread() is returning an empty Mat.
Can you post road.jpg?
Can you give full path as c:/tmp/images/road.jpg ?
@LBerger The image is here.
The absolute path of the image is "E:\Development\opencv-c++-demo\opencv-c++-demo\images\road.jpg"
There is no problem with this image using opencv 4.1.2-dev. Idea to solve your problem :
Move this image on c:\ try to read it.
try to read lena.jpg in opencv/samples/data
...
@LBerger tried but failed to get it to work. I think there is something else going on. Also, kindly check my videos.