opencv 案例出现 terminate called after throwing an instance of 'cv::Exception' what():【解决】


环境:

ubuntu + qt


错误代码:

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /usr/local/opencv/opencv-3.2.0/modules/highgui/src/window.cpp, line 565

terminate called after throwing an instance of 'cv::Exception'

what():  /usr/local/opencv/opencv-3.2.0/modules/highgui/src/window.cpp:565: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow


我在安装完opencv时候,网上写了一个测试的代码如下,结果出现了上面的错误。


示例代码:

#include "mainwindow.h"

#include <QApplication>

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

using namespace cv;


int main()

{

    IplImage *img = 0;

    img = cvLoadImage("/root/Desktop/h3.jpg",-1);    //tong.bmp在所建工程的目录下

    cvNamedWindow("tong", 1);

    cvShowImage("tong", img);

    cvWaitKey(0);

    return 0;

}


解决方法:

根据错误提示,我又安装了libgtk2.0-dev 和 pkg-config

sudo apt-get inatall libgtk2.0-dev

sudo apt-get inatall pkg-config


之后重新cmake一下,我在cmake时候又出现了一个错误,如下,这个只是我出现,其他人不一定出现。

ImportError: No module named 'numpy'

先解决这个错误,方法是

sudo apt-get install python-numpy


之后在重新安装opencv,这样再执行上面的程序,就不会报错了,图片能正常显示。

上述情况网上说是当你安装opencv时候,有些时候一些依赖包可能没有安装,但是没有报错,opencv也安装成功了,但是某些功能没法实现。所以编译不会报错,但是执行就报错了。上述的解决方法希望对你有用。


相关文章:

ubuntu14怎么安装opencv【详】

上一篇 下一篇