OpenCV C++ code runs fine in terminal but error in running from eclipse - Ubuntu 12.04

Viewed 1955

I am trying to run C++ OpenCV programs in Eclipse IDE on Ubuntu 12.04 LTS. They run fine when I use the terminal, as shown here-https://help.ubuntu.com/community/OpenCV.

But when I build the same code in Eclipse, I get the following error

Error description-

opengl support available OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/akash/OpenCV/opencv-2.4.7/modules/highgui/src/window.cpp, line 269 terminate called after throwing an instance of 'cv::Exception' what(): /home/akash/OpenCV/opencv-2.4.7/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow


My code is

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>

using namespace std;
using namespace cv;

int main()
{

    Mat img=imread("image.jpg");
    namedWindow("win",WINDOW_AUTOSIZE);
    imshow("win",img);
    waitKey(0);
    return 1;

}

I have taken care of the following-

  1. kept the image.jpg in src and all other folders of the project.
  2. double-checked the library names in /usr/local/lib
  3. Added only a single include path for OpenCV header files.

I still cant seem to run it.

Please help.

2 Answers
Related