imread function not working

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

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 close merge delete

Comments

1

try: if ( img.empty() ) instead

berak gravatar imageberak ( 2013-06-15 14:22:22 -0500 )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 -0500 )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 -0500 )edit