在Ubuntu 18.04上安装qt和opencv3.4.1

1.查看python版本

$ python3 --version

Python 3.6.5

 

2.

$ python3

>> print("OpenCV + Ubuntu 18.04!")

OpenCV + Ubuntu 18.04!

>> quit()

 

3.

$ sudo apt-get update

$ sudo apt-get upgrade

 

4.

$ sudo apt-get install build-essential cmake unzip pkg-config(重点)

 

$ sudo apt-get install libjpeg-dev libpng-dev libtiff-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 libgtk-3-dev

 

$ sudo apt-get install libatlas-base-dev gfortran

 

$ sudo apt-get install python3-dev

 

4.

 

$ unzip opencv.zip

$ unzip opencv_contrib.zip

 

5.

  sudo apt-get install libopencv-dev(这是我当时缺少的)

   sudo apt-get update

 

 

6.

/opt$ cd opencv

 

/opt/opencv$ mkdir release

 

/opt/opencv$ cd release

 

/opt/opencv/release$ cmake -D BUILD_TIFF=ON -D WITH_CUDA=OFF -D ENABLE_AVX=OFF -D WITH_OPENGL=OFF -D WITH_OPENCL=OFF -D WITH_IPP=OFF -D WITH_TBB=ON -D BUILD_TBB=ON -D WITH_EIGEN=OFF -D WITH_V4L=OFF -D WITH_VTK=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib/modules /opt/opencv/

 

/opt/opencv/release$ make -j4

 

/opt/opencv/release$ make install

 

/opt/opencv/release$ ldconfig

 

/opt/opencv/release$ exit

 

/opt/opencv/release$ cd ~

 

安装完毕

 

安装qt

 

打开QtCreator,点击File,选择New File or Project,选择None-Qt Project,选择Plain C++ Project,点击choose ,然后基本都选默认的就行。项目建立完成后就会看到一个*.pro文件,修改.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

将下面的cpp文件copy main.cpp中:

 

#include  

int main()  

{  

    cv::Mat image = cv::imread("/home/Picture/153.jpg", cv::IMREAD_COLOR);  

    cv::imshow("Hepburn",image);  

    cv::waitKey(0);  

    return 0;

}

 

你可能感兴趣的:(linux)