Ubuntu上Qt5+OpenCV配置

sudo apt install qt5-defult qt5creator

1、在编译 OpenCV 时,勾选BUILD _opencv_world

Tip: 如果使用的是 OpenCV4 ,在 Cmake 编译时可以加上 -DBUILD_PKGCONFIG=ON选项,否则无法通过pkg-config命令调用OpenCV

2、创建opencv.pri文件,内容如下:

OpenCV 3

INCLUDEPATH += /usr/local/include

LIBS += -L/usr/local/lib/ \
     -lopencv_world

CONFIG += link_pkgconfig
PKGCONFIG += opencv

OpenCV 4


INCLUDEPATH += /usr/local/include

LIBS += -L/usr/local/lib/opencv4 \
       -lopencv_world

CONFIG += link_pkgconfig
PKGCONFIG += opencv4

3、创建 Qt 项目,在*.pro文件的最后添加

include(PATH/opencv.pri)

或在*.pro的最后添加如下代码:

win32:{
	include("*/opencv.pri")
}

unix: !macx{
	CONFIG += link_pkgconfig
	PKGCONFIG += opencv
}

unix: macx{
	INCLUDEPATH += "/usr/local/include"
	LIBS += -L"/usr/local/lib/" \
        -lopencv_world
}

你可能感兴趣的:(初始化配置,opencv,ubuntu,qt)