简体   繁体   English

OpenCV C ++代码在终端运行良好但从eclipse运行时出错 - Ubuntu 12.04

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

I am trying to run C++ OpenCV programs in Eclipse IDE on Ubuntu 12.04 LTS. 我试图在Ubuntu 12.04 LTS上的Eclipse IDE中运行C ++ OpenCV程序。 They run fine when I use the terminal, as shown here- https://help.ubuntu.com/community/OpenCV . 他们运行正常,当我使用的终端,如这里- https://help.ubuntu.com/community/OpenCV

But when I build the same code in Eclipse, I get the following error 但是当我在Eclipse中构建相同的代码时,我收到以下错误

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 opengl支持可用OpenCV错误:imshow中的断言失败(size.width> 0 && size.height> 0),文件/home/akash/OpenCV/opencv-2.4.7/modules/highgui/src/window.cpp,第269行在抛出'cv :: Exception'的实例后调用终止what():/ home / kash / OpenCV / opencv-2.4.7 / modules / highgui / src / window.cpp:269:error:( - 1515)size。函数imshow中的width> 0 && size.height> 0


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. 保留了src中的image.jpg和项目的所有其他文件夹。
  2. double-checked the library names in /usr/local/lib 双重检查/ usr / local / lib中的库名称
  3. Added only a single include path for OpenCV header files. 仅为OpenCV头文件添加了一个包含路径。

I still cant seem to run it. 我似乎仍然无法运行它。

Please help. 请帮忙。

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). 我仍然认为你的问题来自程序没有找到image.jpg文件(即使你已经采取了一些步骤来确保它确实)。 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). 工作目录 - 从中​​执行应用程序 - 通常不同于eclipse中的源文件夹或二进制文件夹(您可以在项目设置中手动设置它)。

To quickly verify this hypothesis you could pass the absolute path of image.jpg to imread() . 要快速验证此假设,您可以将image.jpg的绝对路径传递给imread() If that solves the problem you just need to configure your working directory correctly in eclipse. 如果这解决了问题,您只需要在eclipse中正确配置工作目录。

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 多数民众赞成!...享受

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM