Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Imread does not read the file

OpenCV version: 4.0.1
IDE: Visual Studio 2017

I took code from https://docs.opencv.org/4.0.1/db/deb/tutorial_display_image.html
Here is the project Debug folder, it has the logo file.png and test.jpg

image description

The application is compiled in debug folder.

image description

But when I try to run the application and display one of the images in the application folder, the application writes that imread cannot open the image.

image description

Please help.

Imread does not read the file

OpenCV version: 4.0.1
IDE: Visual Studio 2017

I took code from https://docs.opencv.org/4.0.1/db/deb/tutorial_display_image.html
Here is the project Debug folder, it has the logo file.png and test.jpg

image descriptionScreenshot 1

The application is compiled in debug folder.

image descriptionScreenshot 2

But when I try to run the application and display one of the images in the application folder, the application writes that imread cannot open the image.

image descriptionScreenshot 3

Please help.

Imread does not read the file

OpenCV version: 4.0.1
IDE: Visual Studio 2017

I took code from https://docs.opencv.org/4.0.1/db/deb/tutorial_display_image.html
Here is the project Debug folder, it has the logo file.png and test.jpg

Screenshot 1

The application is compiled in debug folder.

Screenshot 2

But when I try to run the application and display one of the images in the application folder, the application writes that imread cannot open the image.

Screenshot 3

EDIT:

This code shows whether the file is available before imread starts opening it.

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <fstream>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
    String imageName("C:\\Users\\Emilia\\Desktop\\VS\\imageFolder\\image.jpg"); // by default
    ifstream input(imageName);
    if (input)
    {
        if (input)
        {
            cout << "Ok! file exists...\n";
        }
        else
        {
            cout << "Oops! file not exists...\n";
            return -1;
        }
    }
    input.close(); //close file
    Mat image;
    image = imread(imageName, IMREAD_COLOR); // Read the file
    if (image.empty())                      // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }
    namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image);                // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

Here's what the program shows

Screenshot 4

Please help.