[环境配置]Ubuntu 16.04 源码编译安装OpenCV-3.2.0+OpenCV_contrib-3.2.0及产生的问题

1.OpenCV-3.2.0+OpenCV_contrib-3.2.0编译安装过程

1)下载官方要求的依赖包

  • GCC 4.4.x or later
  • CMake 2.6 or higher
  • Git
  • GTK+2.x or higher, including headers (libgtk2.0-dev) # 控制opencv GUI
  • pkg-config
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
  • [optional] libtbb2 libtbb-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev # 处理图像所需的包
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
$ sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
$ sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
$ sudo apt-get install ffmpeg

2)下载OpenCV-3.2.0+OpenCV_contrib-3.2.0

$ cd /the_path_you_would_install
$ wget https://github.com/opencv/opencv/archive/3.2.0.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip

直接右键解压,然后进行安装。

$ cd opencv-3.2.0
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules/ ..
$ make -j8 #如果线程足够多可以使用 make -j12
$ sudo make install

第四行最后的 .. 一定不能忘记,因为我们是在/build文件夹中编译上层文件夹的程序。

$ sudo ldconfig -v
$ pkg-config --modversion opencv #确认OpenCV的版本,如果显示3.2.0说明安装完成

2.遇到的问题及解决方案

1)关于opencv_lapack.h缺失的问题

问题如下

In file included from /home/yao/opencv-3.2.0/modules/core/src/hal_internal.cpp:49:0:
/home/yao/opencv-3.2.0/build/opencv_lapack.h:2:45: fatal error: LAPACKE_H_PATH-NOTFOUND/lapacke.h: No such file or directory
compilation terminated.
modules/core/CMakeFiles/opencv_core.dir/build.make:114: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o‘ failed
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....

[ 27%] Built target pch_Generate_opencv_test_optflow
[ 27%] Built target pch_Generate_opencv_perf_optflow
[ 27%] Built target pch_Generate_opencv_test_phase_unwrapping
[ 27%] Built target pch_Generate_opencv_phase_unwrapping
[ 27%] Built target pch_Generate_opencv_test_stitching
[ 27%] Built target pch_Generate_opencv_test_structured_light
[ 27%] Built target pch_Generate_opencv_stitching
[ 27%] Built target pch_Generate_opencv_perf_stitching
[ 27%] Built target pch_Generate_opencv_structured_light
CMakeFiles/Makefile2:1901: recipe for target ‘modules/core/CMakeFiles/opencv_core.dir/all‘ failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:160: recipe for target ‘all‘ failed
make: *** [all] Error 2

解决方案

$ sudo apt-get install liblapacke-dev checkinstall
  • 在/build文件夹中找到opencv_lapack.h文件,把#include "LAPACKE_H_PATH-NOTFOUND/lapacke.h"改为#include "lapacke.h"
  • 重新编译

(2)CUDA 9.0环境下cmake编译时产生的问题

问题如下

在cmake时会产生关于CUDA版本的问题,这种情况在已装CUDA的条件下会出现,未安装时不会有。

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
linked by target "opencv_cudev" in directory

这是由于CUDA 9.0不支持2.0架构,尝试过网上其他方法,包括在cmake时给命令行加入配置属性如CUDA的路径以及配置,皆无效,而以下方案有效。

解决方案:

1) 在/opencv-3.2.0/cmake文件夹下找到FindCUDA.cmake文件

  • 找到
find_cuda_helper_libs(nppi)

改为

 find_cuda_helper_libs(nppial)
  find_cuda_helper_libs(nppicc)
  find_cuda_helper_libs(nppicom)
  find_cuda_helper_libs(nppidei)
  find_cuda_helper_libs(nppif)
  find_cuda_helper_libs(nppig)
  find_cuda_helper_libs(nppim)
  find_cuda_helper_libs(nppist)
  find_cuda_helper_libs(nppisu)
  find_cuda_helper_libs(nppitc)
  • 找到
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")

改为

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
  • 找到
unset(CUDA_nppi_LIBRARY CACHE)

改为

unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)

2) 找到文件OpenCVDetectCUDA.cmake

删除以下几句

if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0")

然后将下一行的elsif改为if

3) 找到文件opencv\modules\cudev\include\opencv2\cudev\common.hpp

添加头文件

#include <cuda_fp16.h>

(3)不支持的GPU architecture问题

问题如下

nvcc fatal : Unsupported gpu architecture ‘compute_20‘

解决方案

在cmake的时候命令行的参数中加入如下一句

-D CUDA_GENERATION=Kepler 

(4)编译到99%或100%时卡住的问题

问题如下

[100%] Built target opencv_perf_stitching
[100%] Built target opencv_python2

这个时候,会一直卡着

解决方案

  • 不要终止安装,等一等,或者make -j8甚至make -j12多线程安装可以快一点,一般几分钟可以安装完成

5)在CMakeLists.txt中设置指定的OpenCV版本

解决方案

set(OpenCV_DIR "/your_opencv_path/opencv-3.2.0/build")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

其中your_opencv_path指你的opencv的安装路径,注意区分大小写。

原文地址:https://www.cnblogs.com/RichardYao/p/9900268.html

时间: 2024-12-26 01:04:30

[环境配置]Ubuntu 16.04 源码编译安装OpenCV-3.2.0+OpenCV_contrib-3.2.0及产生的问题的相关文章

Ubuntu 16.04 源码编译安装PHP7

一.下载PHP7的最新版源码 php7.0.9  下载地址 http://php.net/get/php-7.0.9.tar.gz/from/a/mirror 二.解压 tar -zxf /tmp/php-7.0.9.tar.gz 三.安装相关依赖库 sudo apt-get update sudo apt-get install libxml2-dev #安装gcc sudo apt-get install build-essential sudo apt-get install openss

ubuntu 16.04源码编译和配置caffe详细教程 | Install and Configure Caffe on ubuntu 16.04

本文首发于个人博客https://kezunlin.me/post/b90033a9/,欢迎阅读! Install and Configure Caffe on ubuntu 16.04 Series Part 1: Install and Configure Caffe on windows 10 Part 2: Install and Configure Caffe on ubuntu 16.04 Guide requirements: NVIDIA driver 396.54 CUDA 8

[Part 3] 在Ubuntu 16.04源码编译PCL 1.8.1支持VTK和QT

本文首发于个人博客https://kezunlin.me/post/137aa5fc/,欢迎阅读! Part-3: Install and Configure PCL 1.8.1 with vtk qt support on Ubuntu 16.04 from source Series Part-1: Install and Configure Qt5 on Ubuntu 16.04 Part-2: Install and Configure VTK 8.1.0 from source wit

linux源码编译安装OpenCV

为了尽可能保证OpenCV的特性,使用OpenCV源码编译安装在linux上.先从安装其依赖项开始,以ubuntu 14.04.X为例讲解在Linux上源码编译安装OpenCV,其他linux版本可以类比安装.此文针对,有一点Linux常识(会使用终端)的读者. 源代码准备 如果不想在安装过程中,一步步的下载.编译.安装,可以先一次性下载完需要用到的源代码. X264: ftp://ftp.videolan.org/pub/videolan/x264/snapshots/ FFMPEG: htt

ubuntu 14.04 源码编译postgresql

环境 ubuntu 14.04 桌面版 postgresql 源码下载链接,本教程是使用postgresql 9.3.4 进行编译的 http://www.postgresql.org/ftp/source/ 首先我们需要给ubuntu 安装几个包,因为 postgresql 编译时依赖 install libreadline > apt-get install libreadline6 libreadline6-dev install zlib > apt-get install zlib1

ubuntu linux下源码编译安装lamp环境

安装zlib库 tar -zvxf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make && make install 2.安装apache2.4.23 tar -zvxf httpd-2.4.23.tar.gz cd httpd-2.2.23 ./configure  --prefix=/usr/local/http2 \ --enable-modules=all \          //支持动态,静态加载模块 --enable-rewri

Ubuntu14.04 源码编译安装ejabberd15.04

一.环境 1.系统:Ubuntu14.04_x64 二.下载 1. yaml-0.1.5:链接: http://pan.baidu.com/s/1sj8zGg1 密码: c8ah 2. expat-2.1.0:链接: http://pan.baidu.com/s/1qWE7zmk 密码: 484h 3. libiconv-1.14:链接: http://pan.baidu.com/s/1i3zmBdz 密码: jie2 4.otp_src_17.5:链接: http://pan.baidu.co

Ubuntu/CentOS下源码编译安装Php 5.6基本参数

先确认安装libxml2 apt-get install libxml2 libxml2-dev或者yum install libxml2 libxml2-dev ./configure --prefix=/usr/local/include/php --with-pdo-mysql --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-zlib-dir --enable-xml --enable-bcmath

CentOS 6.5源码编译安装MySQL 5.6

对于服务器的环境,个人觉得还是源码编译安装的非常靠谱,假如有服务器要变更,直接rm掉安装目录即可.有些人喜欢yum安装,但是在卸载yum remove的时候,一不小心,就卸载了一个基础库,导致系统的shell命令失效,情节严重的可能连系统启动都会存在问题. 1. 安装系统的一些必要基础库 yum -y install  gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtoo