linux下qt+opencv环境搭建

环境:ubuntu16.04
qt:qt5.5.1
opencv:opencv3.4.1

一.qt的安装:

https://blog.csdn.net/chengziwang/article/details/112132019

二.opencv的安装:

https://blog.csdn.net/chengziwang/article/details/112145116

三.qt+opencv环境的搭建:

(1)进入qt创建新project:
linux下qt+opencv环境搭建_第1张图片
然后添加如下代码:

#include 
int main()
{
    cv::Mat image = cv::imread("/home/wang/pp.png", cv::IMREAD_COLOR);
    cv::imshow("Lena",image);
    cv::waitKey(0);
    return 0;
}

/home/wang/pp/png为要读入的图片的路径。
(2)点开test_qt.pro文件:
linux下qt+opencv环境搭建_第2张图片
添加如下内容:

INCLUDEPATH +=  /home/wang/opencv/install/include\
                /home/wang/opencv/install/include/opencv \
                /home/wang/opencv/install/include/opencv2

LIBS += /home/wang/opencv/install/lib/libopencv_highgui.so \
        /home/wang/opencv/install/lib/libopencv_core.so    \
        /home/wang/opencv/install/lib/libopencv_imgproc.so \
        /home/wang/opencv/install/lib/libopencv_imgcodecs.so

指定了头文件的位置与动态链接库的位置。
/home/wang/opencv/install即为自己指定的安装opencv的目录。
然后点击运行即可。
参考:https://blog.csdn.net/weixin_39732260/article/details/104148956?ops_request_misc=%25257B%252522request%25255Fid%252522%25253A%252522160963784916780273610935%252522%25252C%252522scm%252522%25253A%25252220140713.130102334.pc%25255Fall.%252522%25257D&request_id=160963784916780273610935&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_v2~rank_v29-6-104148956.first_rank_v2_pc_rank_v29&utm_term=linux%E4%B8%8Bqt+opencv%E5%AE%89%E8%A3%85

你可能感兴趣的:(linux下qt+opencv环境搭建)