本机环境:ubuntu18.04+qt5.9+opencv3.4
参考博客:
Ubuntu16.04 安装 OpenCV3.2.0与QTcreator5.7
QT+OPENCV环境搭建 用的vs2017,编译器用的MinGw
Ubuntu 16.04 + Qt 5.11 +opencv 3.4完美配置(亲测,最简单完美的方法)
一.环境配置
可以运行下文demo,如果出现找不到函数定义
只需要在pro文件的末尾,加上
INCLUDEPATH += /usr/local/include \ /usr/local/include/opencv \ /usr/local/include/opencv2 LIBS += /usr/local/lib/libopencv_calib3d.so \ /usr/local/lib/libopencv_core.so \ /usr/local/lib/libopencv_highgui.so \ /usr/local/lib/libopencv_imgproc.so \ /usr/local/lib/libopencv_imgcodecs.so\ /usr/local/lib/libopencv_objdetect.so\ /usr/local/lib/libopencv_photo.so \ /usr/local/lib/libopencv_dnn.so \ /usr/local/lib/libopencv_shape.so\ /usr/local/lib/libopencv_features2d.so \ /usr/local/lib/libopencv_stitching.so \ /usr/local/lib/libopencv_flann.so\ /usr/local/lib/libopencv_superres.so \ /usr/local/lib/libopencv_videoio.so \ /usr/local/lib/libopencv_video.so\ /usr/local/lib/libopencv_videostab.so \ /usr/local/lib/libopencv_ml.so
参考博客中说简便写法,只需要把主要文件名写出来,但我还是列出了完整的写法,需要自取

INCLUDEPATH += /usr/local/include \ /usr/local/include/opencv \ /usr/local/include/opencv2 LIBS += /usr/local/lib/libopencv_calib3d.so \ /usr/local/lib/libopencv_calib3d.so.3.4 \ /usr/local/lib/libopencv_calib3d.so.3.4.4 \ /usr/local/lib/libopencv_core.so \ /usr/local/lib/libopencv_core.so.3.4 \ /usr/local/lib/libopencv_core.so.3.4.4 \ /usr/local/lib/libopencv_dnn.so \ /usr/local/lib/libopencv_dnn.so.3.4 \ /usr/local/lib/libopencv_dnn.so.3.4.4 \ /usr/local/lib/libopencv_features2d.so \ /usr/local/lib/libopencv_features2d.so.3.4 \ /usr/local/lib/libopencv_features2d.so.3.4.4 \ /usr/local/lib/libopencv_flann.so \ /usr/local/lib/libopencv_flann.so.3.4 \ /usr/local/lib/libopencv_flann.so.3.4.4 \ /usr/local/lib/libopencv_highgui.so \ /usr/local/lib/libopencv_highgui.so.3.4 \ /usr/local/lib/libopencv_highgui.so.3.4.4 \ /usr/local/lib/libopencv_imgcodecs.so \ /usr/local/lib/libopencv_imgcodecs.so.3.4 \ /usr/local/lib/libopencv_imgcodecs.so.3.4.4 \ /usr/local/lib/libopencv_imgproc.so \ /usr/local/lib/libopencv_imgproc.so.3.4 \ /usr/local/lib/libopencv_imgproc.so.3.4.4 \ /usr/local/lib/libopencv_ml.so \ /usr/local/lib/libopencv_ml.so.3.4 \ /usr/local/lib/libopencv_ml.so.3.4.4 \ /usr/local/lib/libopencv_objdetect.so \ /usr/local/lib/libopencv_objdetect.so.3.4 \ /usr/local/lib/libopencv_objdetect.so.3.4.4 \ /usr/local/lib/libopencv_photo.so \ /usr/local/lib/libopencv_photo.so.3.4 \ /usr/local/lib/libopencv_photo.so.3.4.4 \ /usr/local/lib/libopencv_shape.so \ /usr/local/lib/libopencv_shape.so.3.4 \ /usr/local/lib/libopencv_shape.so.3.4.4 \ /usr/local/lib/libopencv_stitching.so \ /usr/local/lib/libopencv_stitching.so.3.4 \ /usr/local/lib/libopencv_stitching.so.3.4.4 \ /usr/local/lib/libopencv_superres.so \ /usr/local/lib/libopencv_superres.so.3.4 \ /usr/local/lib/libopencv_superres.so.3.4.4 \ /usr/local/lib/libopencv_videoio.so \ /usr/local/lib/libopencv_videoio.so.3.4 \ /usr/local/lib/libopencv_videoio.so.3.4.4 \ /usr/local/lib/libopencv_video.so \ /usr/local/lib/libopencv_video.so.3.4 \ /usr/local/lib/libopencv_video.so.3.4.4 \ /usr/local/lib/libopencv_videostab.so \ /usr/local/lib/libopencv_videostab.so.3.4 \ /usr/local/lib/libopencv_videostab.so.3.4.4 \
二.demo1读取图片(参考博客3)
工程很简单,先修改pro配置文件,再编写main函数
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp>
using namespace cv; int main() { Mat img = imread("cat.jpg"); line(img,Point(1,1),Point(250,250),Scalar(0,0,255),5);//画一条直线
imshow("可爱的小猫咪", img); waitKey(0); return 0; }
需要注意的是,读取图片的时候,如果像上面的程序一样写相对路径的话,需要将图片放入项目的debug目录下,不能放在源程序所在的目录下。
三.demo2读取视频(参考博客4)