Imread does not read the file [closed]

asked 2019-01-18 08:54:45 -0600

mrjbom gravatar image

updated 2019-01-18 11:33:28 -0600

OpenCV version: 4.0.1
IDE: Visual Studio 2017

I took code from https://docs.opencv.org/4.0.1/db/deb/...
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.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-27 09:12:44.964158

Comments

1

Hi, There is no HappyFish.jpg image inside your folder. Can you verify it?

vps gravatar imagevps ( 2019-01-18 09:17:10 -0600 )edit

Why should I HappyFish.jpg? I pass the path with an argument. I tried changing ../data / HappyFish.jpg to test.jpg, it does not help, the library works badly in all aspects.

mrjbom gravatar imagemrjbom ( 2019-01-18 09:42:19 -0600 )edit
3

Can you add your code in question? I have tried the same code with the same image. It is working for me.

vps gravatar imagevps ( 2019-01-18 09:49:36 -0600 )edit
1

and please, no screenshots of code or error msgs here... ;(

berak gravatar imageberak ( 2019-01-18 09:51:43 -0600 )edit
1

@mrjbom, common fact -- noobs NEVER find their images with a 1st attempt. ;)

( they also NEVER expect this to fail ;( )

verify, where your image REALLY is, and try with an absolute path, like c:/some/folder/my.png

berak gravatar imageberak ( 2019-01-18 10:47:58 -0600 )edit

@berak, lol, here is a screenshot of the path to the photo.
screenshot
My code

mrjbom gravatar imagemrjbom ( 2019-01-18 11:07:28 -0600 )edit
1

@mrjbom, again, while you got all my sympathy, -- please do us all a favour, and replace ALL of those with a TEXT version, so it can be properly indexed for search ( to help other noobs ! ), we can simply quote you correctly, etc.

screenshots are for morons, ONLY, try NOT to be one, please.

berak gravatar imageberak ( 2019-01-18 11:09:42 -0600 )edit
1

@berak Okay, how can I bypass the comment length limit? I can't give you everything in TEXT format, if you review a LIMITED number of characters. How?

mrjbom gravatar imagemrjbom ( 2019-01-18 11:26:23 -0600 )edit
1

no, please edit your question and put it all there (we'll help you with the formatting, promised ;)

berak gravatar imageberak ( 2019-01-18 11:27:42 -0600 )edit
1

@berak, i changed the question, look please.

mrjbom gravatar imagemrjbom ( 2019-01-18 11:34:28 -0600 )edit