ubuntu18上Qt5移植Opencv3.2.0 遇到的坑

ubuntu18上Qt5移植Opencv3.2.0 遇到的坑

编译报错1

  1. 报错信息

    找不到Mat类的定义
    
  2. 检查以下几个地方

    //包含头文件和命名空间
    #include <opencv2/opencv.hpp>
    using namespace cv;
    
    工程文件中添加要链接的库,在原有的内容上添加如下的内容 
    INCLUDEPATH += /usr/local/opencv
    INCLUDEPATH += /usr/local/opencv2
    
    CONFIG(debug, debug|release): {
    LIBS += -L/usr/local/lib \
    -lopencv_core \
    -lopencv_imgproc \
    -lopencv_highgui\
    -lopencv_ml \
    -lopencv_video \
    -lopencv_features2d \
    -lopencv_calib3d\
    -lopencv_objdetect \
    -lopencv_imgcodecs\
    -lopencv_flann
    } else:CONFIG(release, debug|release): {
    LIBS += -L/usr/local/lib \
    -lopencv_core \
    -lopencv_imgproc \
    -lopencv_highgui\
    -lopencv_ml \
    -lopencv_video \
    -lopencv_features2d \
    -lopencv_calib3d\
    -lopencv_objdetect \
    -lopencv_imgcodecs\
    -lopencv_flann
    }
    
    

编译报错2

  1. 报错信息

    17:33:33: Starting /home/linux/study/QOpencv/build-1-OpencvTest-Desktop_Qt_5_14_0_GCC_64bit-Debug/1-OpencvTest ...
    Gtk-Message: 17:33:33.748: Failed to load module "canberra-gtk-module"
    OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/linux/tool/Opencv3/opencv/modules/highgui/src/window.cpp, line 304
    terminate called after throwing an instance of 'cv::Exception'
      what():  /home/linux/tool/Opencv3/opencv/modules/highgui/src/window.cpp:304: error: (-215) size.width>0 && size.height>0 in function imshow
    
    
  2. 解决办法

    $ sudo apt-get install libcanberra-gtk-module 
    

编译报错3

  1. 报错信息

    17:57:16: Starting /home/linux/study/QOpencv/build-1-OpencvTest-Desktop_Qt_5_14_0_GCC_64bit-Debug/1-OpencvTest ...
    OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/linux/tool/Opencv3/opencv/modules/highgui/src/window.cpp, line 304
    terminate called after throwing an instance of 'cv::Exception'
      what():  /home/linux/tool/Opencv3/opencv/modules/highgui/src/window.cpp:304: error: (-215) size.width>0 && size.height>0 in function imshow
    
  2. 解决办法

    图片文件的路径写绝对路径
    

    ubuntu18上Qt5移植Opencv3.2.0 遇到的坑

上一篇:apache kafka & CDH kafka源码编译


下一篇:第一个C语言编译器是怎样编写的?