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