ubuntu下Qt Creator配置opencv

系统: ubuntu 16.04,  opencv版本: 4.1.1

opencv默认安装后的头文件在:

ubuntu下Qt Creator配置opencv_第1张图片

库文件放在:

ubuntu下Qt Creator配置opencv_第2张图片

 

Qt工程的pro配置:

QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle
CONFIG += C++11   //添加对C++11的支持

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as 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 you use 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

INCLUDEPATH += /usr/local/include/opencv4 //添加头文件路径

LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui //添加需要链接的库

SOURCES += main.cpp \
    test.cpp

HEADERS += \
    test.h

 

按照官方教程,显示一张图片

https://docs.opencv.org/master/db/deb/tutorial_display_image.html

#include 
#include 
#include 
#include 
#include 

using namespace std;
int main( int argc, char** argv )
{
    std::string imageName( "../data/lei.jpeg" ); // by default

    if( argc > 1)
    {
        imageName = argv[1];
    }
    cv::Mat image;
    image = cv::imread( imageName, cv::IMREAD_COLOR ); // Read the file
    if( image.empty() )                      // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }
    cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); // Create a window for display.
    cv::imshow( "Display window", image );                // Show our image inside it.
    cv::waitKey(0); // Wait for a keystroke in the window


    return 0;
}

编译并运行即可显示

ubuntu下Qt Creator配置opencv_第3张图片

Qt Creator使用中,如果配置不生效可以试一下在Build菜单中Clean一下工程.

 

你可能感兴趣的:(OpenCV,Linux)