Ubuntu16.04安装Opencv3.4.1教程

一、编译安装

1.官网下载sources版本(For Linux):http://opencv.org/releases.html

2.解压:

1 unzip opencv-3.4.1.zip 

3.进入:

1 cd opencv-3.4.1.zip

4.安装cmake工具:

1 sudo apt-get install cmake

5.安装依赖库:

1 sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev

6.创建编译目录(release)并进入:

1 mkdir release && cd release

7.cmake配置编译:

1 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

8.make编译:

1 make -j$(nproc)
2 // nproc是读取CPU的核心数量 

9.安装:

1 sudo make install

10.环境配置添加库路径(方式一):

1 sudo /bin/bash -c ‘echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf‘

10.环境配置添加库路径(方式二):

1 sudo gedit /etc/ld.so.conf.d/opencv.conf
2 //打开后可能是空文件,在文件内容最后添加
3 /usr/local/lib

11.更新系统库:

1 sudo ldconfig

12.配置bash,执行如下命令

1 sudo gedit /etc/bash.bashrc
2 //在末尾添加
3 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
4 export PKG_CONFIG_PATH  

保存退出,然后执行如下命令使得配置生效

1 sudo source /etc/bash.bashrc
2 //激活配置然后更新database
3 sudo updatedb  

参考:https://blog.csdn.net/keith_bb/article/details/52685231

二、测试

在home下新建文件夹进入并新建名称为opencv_test.cpp

 1 #include <iostream>
 2 #include <opencv2/opencv.hpp>
 3
 4 using namespace cv;
 5 using namespace std;
 6
 7 int main(int argc, char** argv)
 8 {
 9
10     if ( argc != 2 )
11     {
12         cout << "Need to load a picture..." << endl;
13         return -1;
14     }
15     Mat image;
16     image = imread( argv[1], 1 );
17     if ( image.empty() )
18     {
19         cout<<"No image data!"<< endl;
20         return -1;
21     }
22     namedWindow("Display Image", WINDOW_AUTOSIZE );
23     imshow("Display Image", image);
24     waitKey(0);
25     return 0;
26 }

建立一个CMakeLists.txt文件:

1 cmake_minimum_required(VERSION 2.8)
2
3 project( DisplayImage )
4
5 find_package( OpenCV REQUIRED )
6
7 add_executable( opencv_test opencv_test.cpp )
8
9 target_link_libraries( opencv_test ${OpenCV_LIBS} )

在桌面上放一张测试的图片,例如test.jpg,分别执行

1 cmake .
2
3 make
4
5 ./opencv_test test.jpg

即可显示图片

三、问题记录

1.Qt5Core编译错误

  1 CMake Warning at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
  2 By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
  3 asked CMake to find a package configuration file provided by "Qt5Core", but
  4 CMake did not find one.
  5
  6 Could not find a package configuration file provided by "Qt5Core" with any
  7 of the following names:
  8
  9 Qt5CoreConfig.cmake
 10 qt5core-config.cmake
 11
 12 Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set
 13 "Qt5Core_DIR" to a directory containing one of the above files.  If
 14 "Qt5Core" provides a separate development package or SDK, be sure it has
 15 been installed.
 16 Call Stack (most recent call first):
 17 CMakeLists.txt:466 (include)
 18
 19 CMake Warning at cmake/OpenCVFindLibsGUI.cmake:19 (find_package):
 20 By not providing "FindQt5Gui.cmake" in CMAKE_MODULE_PATH this project has
 21 asked CMake to find a package configuration file provided by "Qt5Gui", but
 22 CMake did not find one.
 23
 24 Could not find a package configuration file provided by "Qt5Gui" with any
 25 of the following names:
 26
 27   Qt5GuiConfig.cmake
 28   qt5gui-config.cmake
 29
 30 Add the installation prefix of "Qt5Gui" to CMAKE_PREFIX_PATH or set
 31 "Qt5Gui_DIR" to a directory containing one of the above files.  If "Qt5Gui"
 32 provides a separate development package or SDK, be sure it has been
 33 installed.
 34 Call Stack (most recent call first):
 35 CMakeLists.txt:466 (include)
 36
 37
 38 CMake Warning at cmake/OpenCVFindLibsGUI.cmake:20 (find_package):
 39 By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
 40 has asked CMake to find a package configuration file provided by
 41 "Qt5Widgets", but CMake did not find one.
 42
 43 Could not find a package configuration file provided by "Qt5Widgets" with
 44 any of the following names:
 45
 46   Qt5WidgetsConfig.cmake
 47   qt5widgets-config.cmake
 48
 49 Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
 50 "Qt5Widgets_DIR" to a directory containing one of the above files.  If
 51 "Qt5Widgets" provides a separate development package or SDK, be sure it has
 52 been installed.
 53
 54 Call Stack (most recent call first):
 55
 56   CMakeLists.txt:466 (include)
 57
 58 CMake Warning at cmake/OpenCVFindLibsGUI.cmake:21 (find_package):
 59
 60   By not providing "FindQt5Test.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt5Test", but
 61
 62   CMake did not find one.
 63
 64   Could not find a package configuration file provided by "Qt5Test" with any
 65
 66   of the following names:
 67
 68 Qt5TestConfig.cmake
 69 qt5test-config.cmake
 70
 71 Add the installation prefix of "Qt5Test" to CMAKE_PREFIX_PATH or set
 72 "Qt5Test_DIR" to a directory containing one of the above files.  If
 73 "Qt5Test" provides a separate development package or SDK, be sure it has
 74 been installed.
 75 Call Stack (most recent call first):
 76   CMakeLists.txt:466 (include)
 77
 78
 79 CMake Warning at cmake/OpenCVFindLibsGUI.cmake:22 (find_package):
 80   By not providing "FindQt5Concurrent.cmake" in CMAKE_MODULE_PATH this
 81   project has asked CMake to find a package configuration file provided by
 82   "Qt5Concurrent", but CMake did not find one.
 83
 84   Could not find a package configuration file provided by "Qt5Concurrent"
 85   with any of the following names:
 86
 87     Qt5ConcurrentConfig.cmake
 88     qt5concurrent-config.cmake
 89
 90   Add the installation prefix of "Qt5Concurrent" to CMAKE_PREFIX_PATH or set
 91   "Qt5Concurrent_DIR" to a directory containing one of the above files.  If
 92   "Qt5Concurrent" provides a separate development package or SDK, be sure it
 93   has been installed.
 94   Call Stack (most recent call first):
 95   CMakeLists.txt:466 (include)
 96
 97 qmake: could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake‘: No such file     or         directory
 98 CMake Error at /usr/share/cmake-2.8/Modules/FindQt4.cmake:1386 (message):
 99   Found unsuitable Qt version "" from NOTFOUND, this code requires Qt 4.x
100 Call Stack (most recent call first):
101   cmake/OpenCVFindLibsGUI.cmake:34 (find_package)
102   CMakeLists.txt:466 (include)
103
104 -- Configuring incomplete, errors occurred!
105 See also "/home/*******/OpenCV/opencv-2.4.9/build/CMakeFiles/CMakeOutput.log".
106 See also "/home/*******/OpenCV/opencv-2.4.9/build/CMakeFiles/CMakeError.log".

Qt5Core-CMake did not find one

解决方式:

1 qt5-default:sudo apt-get install qt5-default

参考地址:https://stackoverflow.com/questions/24378473/ubuntu-opencv-install-and-setup-qt5

原文地址:https://www.cnblogs.com/Shuqing-cxw/p/9195303.html

时间: 2024-07-31 15:15:25

Ubuntu16.04安装Opencv3.4.1教程的相关文章

Ubuntu16.04安装Hadoop2.7.3教程

Ubuntu16.04安装Hadoop2.7.3 教程 参考厦门大学数据库实验室 http://dblab.xmu.edu.cn/blog/install-hadoop/,遇到相关的地方有改动. 作者:秦景坤 日期:2017-4-20 主要内部包括 环境配置和本地和伪分布 本文档适合于原生Hadoop2,参考相关文档,亲自动手实践来一步一步搭建环境.转载请指明出处. 环境 本教程使用Ubuntu16.04 64位作为系统环境,包括桌面版和server版,其他版本系统,若有差异请自行百度安装教程系

Ubuntu16.04安装opencv-3.4.2

原文链接: https://m.oldpan.me/archives/ubuntu-install-opencv-from-source 第一步:更新我们的系统 sudo apt-get update sudo apt-get upgrade 第二步:安装所有依赖库 # 首先我们先移除系统中已经存在的依赖,这一部必须要做 sudo apt-get remove x264 libx264-dev # 然后安装我们需要的依赖 sudo apt-get install build-essential

ubuntu16.04 安装opencv3.2.0

2.2 安装opencv3.2.0 2.2.1 安装opencv依赖库 在终端输入以下命令,进行安装opencv依赖库: 1. sudo apt-get install build-essential 2. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 3. sudo apt-get install python-dev python-nu

ubuntu16.04 安装opencv3.3

from: http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/ Step #1: Install OpenCV dependencies on Ubuntu 16.04 Most (in fact, all) steps in this tutorial will be accomplished by using your terminal. To start, open up your comm

ubuntu16.04安装opencv3.1.0+Qt5.6.0

安装依赖的库 sudo apt-get install build-essential // 必须的,gcc编译环境 sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev // 必须的,包括cmake等工具 sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg

==原创==Ubuntu14.04安装OPENCV3.0流程及遇到的问题

Ubuntu14.04安装OPENCV3.0流程及遇到的问题 [email protected] http://www.cnblogs.com/mcjj 作者:马春杰杰 2017年6月14日22:38:23 我的电脑环境: Ubuntu14.04LTS + CUDA8.0 + CUDNN5.0 + Nvidia-367.44驱动 + OPENCV3.0-beta 我是按照这篇文章来的: Ubuntu14.04安装OpenCV3.0 - Linux系统教程 首先是刚开始的时候就遇到了错误,Unsu

[教程]Ubuntu16.04安装texstudio

[教程]Ubuntu16.04安装texstudio step 1 首先要下载texlive. 不会的戳这里 然后直接终端命令 sudo apt-get install texstudio step 2 其实最关键的是配置. 首先选择语言: Options->Configure TeXstudio...->General->Language:zh_CN. 如果要支持中文的话,要把命令改为XeLaTeX. 在文件中搜到xelatex的位置,然后在命令里面修改就行了. 然后就基本能用了. 可

Ubuntu16.04安装tensorflow+安装opencv+安装openslide+安装搜狗输入法

Ubuntu16.04在cuda以及cudnn安装好之后,安装tensorflow,tensorflow以及opencv可以到网上下载对应的安装包并且直接在安装包所在的路径下直接通过pip与conda进行安装,如下图所示: 前提是要下载好安装包.安装好tensorflow之后还需要进行在~/.bashrc文件中添加系统路径,如下图所示 Openslide是医学图像一个重要的库,这里给出三条命令进行安装 sudo apt-get install openslide-tools sudo apt-g

Ubuntu16.04安装opencv for python/c++

Ubuntu16.04安装opencv for python/c++ 网上关于opencv的安装已经有了不少资料,但是没有一篇资料能让我一次性安装成功,因此花费了大量时间去解决各种意外,希望这篇能给一些人带去便利,节省时间. 1.安装OpenCV所需的库 1 sudo apt-get install build-essential 2 sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavforma