QT下载:
方法一: 终端输入:(自动安装最新版本)
sudo apt-get update
sudo apt-get install qt5-default qtcreator
方法二:官网安装包下载安装(下载版本选择)
点开链接,根据示例路径(以5.12版本为例)下载安装包:
/5.12/5.12.0/qt-opensource-linux-x64-5.12.0.run
安装: 在安装包位置右键打开终端(修改对应的软件包名称)
sudo chmod +x qt-opensource-linux-x64-5.12.0.run
sudo ./qt-opensource-linux-x64-5.12.0.run
创建帐号可以直接skip,选择安装组件
配置系统路径
sudo vim /etc/bash.bashrc
在文件的最后添加如下内容
export QTDIR=/opt/Qt5.12.0/5.12.0/gcc_64
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH5_:
保存(【:】+【w】+【q】)后执行如下命令
source /etc/bash.bashrc
测试配置
echo $PATH
输出如下内容
/opt/Qt5.12.0/5.12.0/gcc_64/bin:/opt/ros/melodic/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
------------QT安装完成------------
**Opencv4.1.0下载:
其他版本可以**版本选择,找到需要下载的版本按Sources进行下载
配置前先下载cmake
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 update
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev
如果出现“E: 无法定位软件包 libjasper-dev”报错,是因为缺少依赖,终端继续输入
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
安装依赖后再一次输入
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev
QT+Opencv配置:(将opencv压缩包解压,在opencv文件夹中打开终端)
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install
sudo make
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
加入 /usr/local/lib
sudo ldconfig
sudo gedit /etc/bash.bashrc
在最底端写入 :
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
终端输入:
sudo ldconfig
sudo cp /usr/local/include/opencv4/opencv2 /usr/local/include -r
上面一行,可自行顺着路径查看本机文件夹内容,这个操作是为了方便配置好后,QT的pro文件内容更简便
配置好后,进行测试:
.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/libopencv_* \
测试能否调用摄像头:
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture (0);
Mat src;
while(1)
{
capture >> src;
imshow("capture",src);
char(key)=(char)waitKey(1);
if(key==27)
break;
}
return 0;
}
更多资料请点击:我的目录