imread function not working [closed]
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
try:
if ( img.empty() )
insteadand make sure this 'test.jpg' exists at the very same folder you start your program
i think you have to put semicolon (;) after cout<<"Error!\n" I have check this code work OK.