ubuntu下Qt调用openCV

  1. 编译好openCV,看好装到哪了了

  2. pro里面写好链接

    INCLUDEPATH += /usr/include/opencv \
                   /usr/include/opencv2
    
    
    LIBS += /usr/lib/x86_64-linux-gnu/libopencv_highgui.so \
            /usr/lib/x86_64-linux-gnu/libopencv_core.so    \
            /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so \
            /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so
    
  3. 在main里写这个验证一下是否可用

    #include 
    #include 
    #include 
    using namespace cv;
    
    int main()
    {
        Mat img = imread("/home/gsh/QT_Projects/untitled4/0.jpg");
    
        line(img,Point(1,1),Point(250,250),Scalar(0,0,255),5);//画一条直线
        imshow("可爱的小猫咪", img);
        waitKey(0);
        return 0;
    }
    

这样包含文件也行。。。

#引入opnecv库
INCLUDEPATH += /usr/include/opencv
INCLUDEPATH += /usr/include/opencv2
INCLUDEPATH += /usr/include/opencv2/core
INCLUDEPATH += /usr/include/opencv2/highgui
INCLUDEPATH += /usr/include/opencv2/imgproc
INCLUDEPATH += /usr/include/opencv2/flann
INCLUDEPATH += /usr/include/opencv2/photo
INCLUDEPATH += /usr/include/opencv2/video
INCLUDEPATH += /usr/include/opencv2/features2d
INCLUDEPATH += /usr/include/opencv2/objdetect
INCLUDEPATH += /usr/include/opencv2/calib3d
INCLUDEPATH += /usr/include/opencv2/ml
INCLUDEPATH += /usr/include/opencv2/contrib

#LIBS += /usr/lib/x86_64-linux-gnu/libopencv_highgui.so \
#        /usr/lib/x86_64-linux-gnu/libopencv_core.so    \
#        /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so \
#        /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so

#        因为总是少包含头文件,所以发现这个方法也行。。。直接把环境变量下opencv的所有都包含进来
LIBS += `pkg-config opencv --cflags --libs`
#include "cv.h"
#include "highgui.h"

你可能感兴趣的:(OpenCV)