ubuntu 18.04 系统 qt 配置 opencv

1.下载opencv与qt

qt下载    opencv 下载

2.安装qt,./文件 即可安装 解压opencv

3.安装依赖

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 libdc1394-22-dev

4.编译opencv

进入解压文件夹

mkdir build

cd build

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

sudo make -j8

sudo make install

编译中如果报错 ippicv... 下载超时


链接: https://pan.baidu.com/s/1JR3GHfbE7guf0It2an1N3w 提取码: dn87 复制这段内容后打开百度网盘手机App,操作更方便哦
则 
gedit /opencv_source/opencv/3rdparty/ippicv/ippicv.cmake #记得lc换成自己的用户名

将47行进行如下修改


#                 "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/#ippicv/"
		"file:////home/xgs/opencv-3.4.6/"

ubuntu 18.04 系统 qt 配置 opencv_第1张图片

5.配置环境

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/opencv/lib/pkgconfig 

export PKG_CONFIG_PATH 

sudo source /etc/bash.bashrc #使配置生效

6.测试程序

pro文件

QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
        main.cpp

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
LIBS += /usr/local/lib/libopencv*

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

cpp

#include 
#include 
#include 
using namespace cv;
using namespace std;

int main()
{
    Mat img = imread("/home/xgs/test.jpg");

    line(img,Point(0,0),Point(img.cols,img.rows),Scalar(0,255,0),5);//画一条直线
    imshow("dog and cat", img);
    waitKey(0);
    return 0;
}

你可能感兴趣的:(配置教程)