Tegra环境下安装OpenCV

环境:

  • NVIDIA DRIVE™ PX 2 (V4L)
  • NVIDIA® Tegra® Linux Driver Package (L4T)
  • Desktop Linux (Ubuntu 14.04 LTS and 16.04 LTS)  

下载源码:

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_extra.git 

安装前提:
CMake 2.8.10 or newer
CUDA toolkit 8.0 (7.0 or 7.5 may also be used)
Build tools (make, gcc, g++)
Python 2.6 or greater

在linux上编译opencv所需要的软件包:

sudo apt-get install \
    libglew-dev \
    libtiff5-dev \
    zlib1g-dev \
    libjpeg-dev \
    libpng12-dev \
    libjasper-dev \
    libavcodec-dev \
    libavformat-dev \
    libavutil-dev \
    libpostproc-dev \
    libswscale-dev \
    libeigen3-dev \
    libtbb-dev \
    libgtk2.0-dev \
    pkg-config
python-dev / python3-dev
python-numpy / python3-numpy
python-py / python3-py
python-pytest / python3-pytest

$ sudo apt-get install python-dev python-numpy python-py python-pytest
# And, optionally:
$ sudo apt-get install python3-dev python3-numpy python3-py python3-pytest

准备编译目录:

$ mkdir build
$ cd build

编译前的配置:

Drive PX2 平台的配置如下,注意此配置是针对python2的,如果你只想在python3下配置opencv,需要手动修改下面的BUILD_opencv_python2的值为OFF,BUILD_opencv_python3的值为ON。

cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_PNG=OFF \
    -DBUILD_TIFF=OFF \
    -DBUILD_TBB=OFF \
    -DBUILD_JPEG=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_ZLIB=OFF \
    -DBUILD_EXAMPLES=ON \
    -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_python2=ON \
    -DBUILD_opencv_python3=OFF \
    -DENABLE_NEON=ON \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENMP=OFF \
    -DWITH_FFMPEG=ON \
    -DWITH_GSTREAMER=OFF \
    -DWITH_GSTREAMER_0_10=OFF \
    -DWITH_CUDA=ON \
    -DWITH_GTK=ON \
    -DWITH_VTK=OFF \
    -DWITH_TBB=ON \
    -DWITH_1394=OFF \
    -DWITH_OPENEXR=OFF \
    -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
    -DCUDA_ARCH_BIN=6.2 \
    -DCUDA_ARCH_PTX="" \
    -DINSTALL_C_EXAMPLES=ON \
    -DINSTALL_TESTS=OFF \
    -DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
    ../opencv

针对Linux Desktop的配置:

  • Ubuntu Desktop Linux 14.04 LTS
  • Ubuntu Desktop Linux 16.04 LTS
cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_PNG=OFF \
    -DBUILD_TIFF=OFF \
    -DBUILD_TBB=OFF \
    -DBUILD_JPEG=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_ZLIB=OFF \
    -DBUILD_EXAMPLES=ON \
    -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_python2=ON \
    -DBUILD_opencv_python3=OFF \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENMP=OFF \
    -DWITH_FFMPEG=ON \
    -DWITH_GSTREAMER=OFF \
    -DWITH_GSTREAMER_0_10=OFF \
    -DWITH_CUDA=ON \
    -DWITH_GTK=ON \
    -DWITH_VTK=OFF \
    -DWITH_TBB=ON \
    -DWITH_1394=OFF \
    -DWITH_OPENEXR=OFF \
    -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
    -DCUDA_ARCH_BIN='3.0 3.5 5.0 6.0 6.2' \
    -DCUDA_ARCH_PTX="" \
    -DINSTALL_C_EXAMPLES=ON \
    -DINSTALL_TESTS=OFF \
    -DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
    ../opencv

使用make进行编译并安装:

make -j6
sudo make install

CMake 参数指南

Parameter Our Default Value What It Does Notes
BUILD_EXAMPLES ON Governs whether the C/C++ examples are built  
BUILD_JASPER OFF Governs whether the Jasper library (libjasper) is built from source in the 3rdparty directory  
BUILD_JPEG OFF As above, for libjpeg  
BUILD_PNG OFF As above, for libpng  
BUILD_TBB OFF As above, for tbb  
BUILD_TIFF OFF As above, for libtiff  
BUILD_ZLIB OFF As above, for zlib  
BUILD_opencv_java OFF Controls the building of the Java bindings for OpenCV Building the Java bindings requires OpenCV libraries be built for static linking only
BUILD_opencv_nonfree OFF Controls the building of non-free (non-open-source) elements Used only for building 2.4.X
BUILD_opencv_python ON Controls the building of the Python 2 bindings in OpenCV 2.4.X Used only for building 2.4.X
BUILD_opencv_python2 ON Controls the building of the Python 2 bindings in OpenCV 3.1.0 Not used in 2.4.X
BUILD_opencv_python3 OFF Controls the building of the Python 3 bindings in OpenCV 3.1.0 Not used in 2.4.X
CMAKE_BUILD_TYPE Release Selects the type of build (release vs. development) Is generally either Release or Debug
CMAKE_INSTALL_PREFIX /usr Sets the root for installation of the libraries and header files  
CUDA_ARCH_BIN varies Sets the CUDA architecture(s) for which code is compiled Usually only passed for platforms with known specific cards. OpenCV includes a small program that determines the architectures of the system's installed card if you do not pass this parameter. Here, for Ubuntu desktop, the value is a list to maximize card support.
CUDA_ARCH_PTX "" Builds PTX intermediate code for the specified virtual PTX architectures  
CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda-8.0 (for Linux) Specifies the location of the CUDA include files and libraries  
ENABLE_NEON ON Enables the use of NEON SIMD extensions for ARM chips Only passed for builds on ARM platforms
ENABLE_PRECOMPILED_HEADERS OFF Enables/disables support for pre-compiled headers Only specified on some of the ARM platforms
INSTALL_C_EXAMPLES ON Enables the installation of the C example files as part of make install  
INSTALL_TESTS ON Enables the installation of the tests as part of make install  
OPENCV_TEST_DATA_PATH ../opencv_extra/testdata Path to the testdatadirectory in the opencv_extrarepository  
WITH_1394 OFF Specifies whether to include IEEE-1394 support  
WITH_CUDA ON Specifies whether to include CUDA support  
WITH_FFMPEG ON Specifies whether to include FFMPEG support  
WITH_GSTREAMER OFF Specifies whether to include GStreamer 1.0 support  
WITH_GSTREAMER_0_10 OFF Specifies whether to include GStreamer 0.10 support  
WITH_GTK ON Specifies whether to include GTK 2.0 support Only given on Linux platforms, not Microsoft Windows
WITH_OPENCL OFF Specifies whether to include OpenCL runtime support  
WITH_OPENEXR OFF Specifies whether to include ILM support via OpenEXR  
WITH_OPENMP OFF Specifies whether to include OpenMP runtime support  
WITH_TBB ON Specifies whether to include Intel TBB support

https://docs.opencv.org/3.2.0/d6/d15/tutorial_building_tegra_cuda.html#tutorial_building_tegra_cuda_testing

猜你喜欢

转载自blog.csdn.net/wanzew/article/details/81368949