4

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.

1
  • and those header files are as follows- #include <opencv2/highgui/highgui.hpp> #include <opencv2/core/core.hpp> Commented Dec 23, 2013 at 11:17

2 Answers 2

3

I still think your problem comes from the program not finding the image.jpg file (even if you have taken a number of steps to make sure it does). The working directory - that an application is executed from - is often different from that of the source or binary folders in eclipse (you can actually set it manually in project settings).

To quickly verify this hypothesis you could pass the absolute path of image.jpg to imread(). If that solves the problem you just need to configure your working directory correctly in eclipse.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that rectified it. I went into the resource settings and found that it links just to the folder of the project, not the src folder, as I thought it would.
0
g++ filename.cpp -o outputfile-name pkg-config --cflags --libs opencv

Ex:

Compilation:-

thinkpadt61@thinkpadt61-ThinkPad-T61:~/Kannathasan$ g++ simple.cpp -o sample pkg-config --cflags --libs opencv

Run:

thinkpadt61@thinkpadt61-ThinkPad-T61: ./sample

Thats it!... Enjoy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.