Ubuntu 17.04 version, OpenCV to compile the source code to install

Source: Internet
Author: User
Tags git clone gfortran

This article is mainly for Ubuntu 17.04 version, OpenCV to compile the source code to install. The development environment is primarily for Python calls to the OpenCV library.

    1. Installing the GCC cmake compilation environment
sudo apt-get install build-essential pkg-config cmake cmake-gui

This article provides two source code compilation method, one is the CMake command, the other is through the graphical interface of the Cmake-gui to compile

    1. This version of the system Ubuntu already comes with Python 2.7 and Python 3.5, need to install PIP to manage Python package
sudo apt-get install python-pipsudo apt-get install python3-pip
    1. Configure PIP Tsinghua Source Accelerator pack Download Update speed (look for fly-like feeling)
mkdir ~/.pipvim ~/.pip/pip.conf# 在pip.conf 中添加以下内容[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple[install]trusted-host=mirrors.aliyun.com
    1. Install Python and the data analysis package under Python3
pip install numpy scipy matplotlib scikit-image scikit-learn pip3 install numpy scipy matplotlib scikit-image scikit-learn
在这一步时出现了问题,参考
    1. Install other dependencies
# git : 版本控制# gfortran fortran编译器# yasm 汇编编译器# ffmpeg 系统自带sudo apt-get install checkinstall yasm gfortran git ffmpegsudo apt-get install libxvidcore4 libgtk-3-devsudo apt-get install libjpeg8-dev libjasper-dev sudo apt-get install libtiff5-devsudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-devsudo apt-get install libxine2-dev libv4l-devsudo apt-get install libqt4-dev libgtk2.0-dev libtbb-devsudo apt-get install libatlas-base-devsudo apt-get install libfaac-dev libmp3lame-dev libtheora-devsudo apt-get install libvorbis-dev libxvidcore-devsudo apt-get install libopencore-amrnb-dev libopencore-amrwb-devsudo apt-get install x264 v4l-utils
    1. Optional dependencies
sudo apt-get install libprotobuf-dev protobuf-compilersudo apt-get install libgoogle-glog-dev libgflags-devsudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
    1. Download and install OpenCV3
    • Install Git
      sudo apt-get install git
    • Download OpenCV3
      git clone https://github.com/opencv/opencv.git
    • Download Opencv_contrib
      git clone https://github.com/opencv/opencv_contrib.git

OpenCV, starting with 3.0, separates part of the content (such as SIFT, etc.) into Opencv_contrib. Therefore, to fully install the OpenCV, you will also need to install Opencv_contrib.

    1. Command compilation
cd opencvmkdir buildcd buildcmake -D CMAKE_BUILD_TYPE=RELEASE       -D CMAKE_INSTALL_PREFIX=/usr/local       -D INSTALL_C_EXAMPLES=ON       -D INSTALL_PYTHON_EXAMPLES=ON       -D WITH_TBB=ON       -D WITH_V4L=ON       -D WITH_QT=ON       -D WITH_OPENGL=ON       -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules       -D BUILD_EXAMPLES=ON ..# 查看cpu 核心数nproc# 如果你有8个核心 # 切换至 build 目录中,执行下面命令,编译源码并链接生成相应的动态库以及可执行文件make -j8# 执行完成后,再执行以下命令,将生成的可执行文件以及动态库安装到指定的安装目录中。sudo make installsudo sh -c ‘echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf‘sudo ldconfig
    1. Configure build makefile with graphical tools
    • Switch to the OPENCV directory and create a new directory to hold the CMake generated configuration file.
      mkdir build
      cd build

    • Find Cmake-gui Open in the software of your GUI

      Then add the OpenCV directory path in the where is the source code and add the new build directory in the where to build the binaries

    • Then click on the Configure below, select Unix makefiles, then select Default .... Click OK to process the CMakeLists.txt in the OpenCV directory. and generate files such as CMakeCache.txt and Makefile in the build directory.

    • After the Configure configuration is complete, a configuration interface similar to the following will appear



Here are the sections that need to be modified

CMAKE_BUILD_TYPE 修改为 RELEASEOPENCV_EXTRA_MODULES_PATH 设为 opencv_contrib 中的 modules 目录的路径(比如,/home/arvin/opencv_contrib/modules)在 BUILD_EXAMPLES 的复选框里 打勾在 INSTALL_C_EXAMPLES 的复选框里 打勾在 INSTALL_PYTHON_EXAMPLES 的复选框里 打勾在 WITH_FFMPEG 的复选框里 打勾在 WITH_GTK 的复选框里 打勾在 WITH_V4L 的复选框里 打勾在 WITH_TIFF 的复选框里 打勾在 WITH_PNG 的复选框里 打勾在 WITH_JPEG 的复选框里 打勾在 WITH_JASPER 的复选框里 打勾取消 WITH_CUDA 的复选框里的勾取消 WITH_CUFFT 的复选框里的勾
    • Then click Configure, apply the changes you just made and update the changes to the CMakeCache.txt in the build directory. Then click Generate to update Makefile.

    • Install additional packages for OpenCV3 and OpenCV3

      cd opencv/build/
      make -j8
      sudo make install
       sudo ldconfig
    1. Test environment is configured successfully
# 在命令行打开你的python 解释器,输入以下命令import cv2 print cv2.__version__# 若看到类似以下输出,则表示配置成功‘3.3.0-dev‘

Ubuntu 17.04 version, OpenCV to compile the source code to install

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.