OpenCV C ++ code works fine in terminal, but error when starting from eclipse - Ubuntu 12.04

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

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

Error Description -

opengl support available OpenCV error: approval 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 call after calling '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 the imshow function


My code

#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 took care of the following -

  • saved image.jpg in src and all other project folders.
  • double checked library names in / usr / local / lib
  • Only one include path has been added for OpenCV header files.

I still can not start it.

Please, help.

+4
source share
2 answers

, , image.jpg( , ). , , eclipse ( ).

, image.jpg imread(). , eclipse.

+3
g++ filename.cpp -o outputfile-name pkg-config --cflags --libs opencv

:

: -

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

Run:

thinkpadt61@thinkpadt61-ThinkPad-T61: ./sample

!...

0

All Articles