ubuntu18.04+qt+opencv安装记录

1.qt下载

下载地址:http://download.qt.io/archive/qt/

配置:

sudo apt-get install build-essential
sudo apt-get install libX11-dev libXext-dev libXtst-dev
sudo apt-get install libx11-dev libxau-devlibxaw7-dev libxcb1-dev libxcomposite-dev libxcursor-devlibxdamage-dev libxdmcp-dev
sudo apt-get install libxext-dev libxfixes-devlibxfont-dev libxft-dev libxi-dev libxinerama-dev libxkbfile-devlibxmu-dev libxmuu-dev
sudo apt-get install libxpm-dev libxrandr-devlibxrender-dev libxres-dev libxss-dev libxt-dev libxtst-dev libxv-devlibxvmc-dev
sudo apt-get install libglib2.0-dev
sudo apt-get install libssl-dev
sudo apt-get install libcups2-dev
sudo apt-get install libgl1-mesa-devlibglu1-mesa-dev
sudo apt-get install libgstreamer0.10-dev

安装:

#自行更改下载qt文件
sudo chmod +x qt-opensource-linux-x64-5.3.0.run    
sudo ./qt-opensource-linux-x64-5.3.0.run

路径配置:

sudo gedit /etc/bash.bashrc
#在末尾添加
export QTDIR=/opt/Qt5.3.0/5.3/gcc_64 #根据自已的具体版本
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
#保存并退出
source /etc/bash.bashrc
sudo updatedb

 

2.opencv+opencv-contrib安装

参考案例:https://www.jianshu.com/p/2975af275871

opencv3.4.2下载地址:https://github.com/opencv/opencv/releases/tag/3.4.2

opencv-contrib3.4.2下载地址:https://github.com/opencv/opencv_contrib/releases/tag/3.4.2

ubuntu18.04+qt+opencv安装记录_第1张图片

需安装的依赖库有:

ubuntu18.04+qt+opencv安装记录_第2张图片

依赖库安装:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip
sudo apt-get install python3-dev
sudo pip3 install numpy
sudo pip3 install scipy
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install build-essential  libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install install libgtk2.0-dev pkg-config

解压压缩包到同一文件夹opencv

cd /opencv_python_path/
mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib_path/modules/ ..
sudo make -j8
sudo make install

错误:

~/opencv_contrib/modules/xfeatures2d/src/boostdesc.cpp:673:20: fatal error: boostdesc_bgm.i: No such file or directory

下载缺失文件,拷贝到opencv_contrib/modules/xfeatures2d/src/ 下

缺失文件下载地址:https://blog.csdn.net/AlexWang30/article/details/99612188

若编译成功,进行环境配置

cd /etc/ld.so.conf.d/
sudo gedit opencv.conf
#创建文件后插入 /usr/local/lib 保存并退出
sudo ldconfig

配置bash:

sudo gedit /etc/bash.bashrc
#在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH 
#保存退出
source /etc/bash.bashrc
sudo updatedb

测试:

ubuntu18.04+qt+opencv安装记录_第3张图片

ubuntu18.04+qt+opencv安装记录_第4张图片

进入qt创建新project:

pro文件修改:

QT += core
QT -= gui

TARGET = opencv_test
CONFIG += console
CONFIG -= app_bundle

INCLUDEPATH += /usr/local/include \
                /usr/local/include/opencv \
                /usr/local/include/opencv2

LIBS += /usr/local/lib/libopencv_highgui.so \
        /usr/local/lib/libopencv_core.so    \
        /usr/local/lib/libopencv_imgproc.so \
        /usr/local/lib/libopencv_imgcodecs.so

TEMPLATE = app

SOURCES += main.cpp

main.cpp测试:

#include 
int main()
{
    cv::Mat image = cv::imread("图片地址", cv::IMREAD_COLOR);
    cv::imshow("Lena",image);
    cv::waitKey(0);
    return 0;
}

 

你可能感兴趣的:(ubuntu18.04+qt+opencv安装记录)