Ask Your Question

Revision history [back]

Image Not Loading In OpenCV 4.x.x

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

[ Copied from Stack Overflow ]

Image Not Loading In OpenCV 4.x.x

[ UPDATE ]

This issue is still unresolved. I have also asked it in the OpenCV forum (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. OpenCV 4.x.x. I have tried 4.0.0 (prebuilt x64 Windows binaries), binaries), 4.1.1(prebuilt x64 Windows binaries) binaries) and 4.1.2(built x64 binaries from source using VS 2019).2019).

Interestingly, the same code works for OpenCV 3.x.x.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 Bit
  • Visual Studio 2019 Community Edition

[ Copied from Stack Overflow ]

Image Not Loading In OpenCV 4.x.x

[ UPDATE ]

This issue is still unresolved. I have also asked it in the OpenCV forum 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