一、qt安装
下载qt安装包qt-opensource-linux-x64-5.12.0.run,直接安装,下一步到底。
下载地址:http://download.qt.io/archive/qt/5.12/5.12.0/
可能出现的问题:
1、新建工程后,工程项目只有.pro文件
解决方法:手动安装gcc与g++编译器,sudo apt-get install gcc g++
2、Error while building/deploying project *** (kit: Desktop Qt 5.7.0 GCC 64bit) When executing step "Make"
解决方法:sudo apt-get install build-essential
3、cannot find -lGL
解决方法:sudo apt-get install libqt4-dev
二、OpenCV安装
1、下载opencv3.4源码
下载地址:https://opencv.org/releases.html
2、安装依赖包
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
3、编译安装
sudo mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install
4、 配置opencv3.4
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
5、注意
为避免出现无法预料的问题,最好把sources拷贝到在Ubuntu里,不要挂载window硬盘安装。
6、测试
在Qt的.pro文件中添加头文件路径和动态链接库
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += /usr/local/lib/lib*
在main中写测试代码
#include "widget.h"
#include <QApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Widget w;
// w.show();
Mat img = imread("1.jpg");
imshow("可爱的小猫咪", img);
waitKey(0);
return a.exec();
}
会显示图片: