Ubuntu编译配置Opencv

Posted ike_li

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu编译配置Opencv相关的知识,希望对你有一定的参考价值。

一、

1.下载opencv源代码

2.安装编译依赖库

 2.1 sudo apt-get update

 2.2 

sudo apt-get install cmake
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
sudo apt-get install build-essential
sudo apt-get install libavcodec-dev
sudo apt-get install libavformat-dev
sudo apt-get install libswscale-dev

3.进入到OpenCV的文件夹中,创建一个build目录,进行编译

3.1.cd opencv-3.4.10
3.2.mkdir build
3.3.cd build
3.4.cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
3.5.make
3.6.sudo make install

 

4.编译完成使用

4.1 一种是配置路径

1.opencv的头文件:/usr/local /include

2.lib 文件,在编译build文件下 :opencv-3.4.10/build/lib

二、

.pro添加opencv库文件

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# 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     mainwindow.cpp

HEADERS +=     mainwindow.h

FORMS +=     mainwindow.ui

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



unix:!macx: LIBS += -L$$PWD/thirdpart/lib/  -lopencv_calib3d  -lopencv_core  -lopencv_dnn  -lopencv_features2d  -lopencv_flann  -lopencv_highgui  -lopencv_imgcodecs  -lopencv_imgproc  -lopencv_ml  -lopencv_objdetect  -lopencv_photo  -lopencv_shape  -lopencv_stitching  -lopencv_superres  -lopencv_ts  -lopencv_video  -lopencv_videoio  -lopencv_videostab 

INCLUDEPATH += $$PWD/thirdpart/include
DEPENDPATH += $$PWD/thirdpart/include

 

#include "mainwindow.h"

#include <QApplication>
#include "opencv2/opencv.hpp"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
//    MainWindow w;
//    w.show();

    // read an image
       cv::Mat image = cv::imread("/home/likewei/Project/OpencvDemo/color3.jpg", 1);
       // create image window named "My Image"
       cv::namedWindow("My Image");
       // show the image on window
       cv::imshow("My Image", image);


    return a.exec();
}

 

以上是关于Ubuntu编译配置Opencv的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu配置Opencv

在 Ubuntu 14.04 上从源代码编译时如何链接到 opencv 3.0?

linux ubuntu16.04 编译opencv教程(没编过,有时间再弄,推流不用opencv也行的)

解决一个Ubuntu中编译NEON优化的OpenCV的错误

在Ubuntu下安装OpenCV并使用

Ubuntu找不到OpenCV里的xml文件