imread function not working [closed]

asked 2013-06-15 14:15:30 -0600

bijan311 gravatar image

updated 2020-09-16 11:57:50 -0600

I am trying to write a basic program in opencv that just displays an image, but imread does not seem to be working.I have libopencv_core.so and libopencv_highgui.so linked to the program and I'm using linux.

Here is my code:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat img = imread("test.jpg", 1);

    if(!img.data)//This if statement is triggered
    {
        cout<<"Error!\n"
        return -1;
    }

    namedWindow("Test", CV_WINDOW_AUTOSIZE);
    imshow("Test", img);

    waitKey(0);

    return 1;
}

Thank you

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-27 09:15:37.258171

Comments

1

try: if ( img.empty() ) instead

berak gravatar imageberak ( 2013-06-15 14:22:22 -0600 )edit
1

and make sure this 'test.jpg' exists at the very same folder you start your program

Guanta gravatar imageGuanta ( 2013-06-15 15:39:55 -0600 )edit
1

i think you have to put semicolon (;) after cout<<"Error!\n" I have check this code work OK.

jigarsen18 gravatar imagejigarsen18 ( 2013-06-17 00:19:04 -0600 )edit