Ubuntu上OpenCV3编译安装详解

目录

一.基础编译

二.CMake参数设置


一.基础编译

1. 环境要求

GCC 4.4.x or later
CMake 2.8.7 or higher
Git
GTK+2.x or higher, including headers (libgtk2.0-dev)
pkg-config
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)        //不编译python版本则不用
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-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

2. 编译安装

        1. 进入你的OpenCV源代码文件夹
        2. 在opencv源代码文件夹中新建build文件夹
        3. 进入build文件夹
        4. 用cmake默认编译
        5. 安装

$ cd ${源文件所在位置}
$ mkdir build
$ cd build
$ cmake ..
$ make -j
$ make install
//至此,opencv被安装到默认位置 /uer/local

二.CMake参数设置

1. 编译命令示例

##示例命令
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
    -DOPENCV_GENERATE_PKGCONFIG=ON \
    -DBUILD_PNG=ON \
    -DBUILD_TIFF=ON \
    -DBUILD_TBB=OFF \
    -DBUILD_JPEG=ON \
    -DBUILD_JASPER=ON \
    -DBUILD_ZLIB=ON \
    -DBUILD_EXAMPLES=ON \
    -DBUILD_JAVA=OFF \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENMP=OFF \
    -DWITH_OPENGL=ON \
    -DOpenGL_GL_PREFERENCE=GLVND \
    -DWITH_FFMPEG=ON \
    -DWITH_GSTREAMER=OFF \
    -DWITH_GSTREAMER_0_10=OFF \
    -DWITH_CUDA=ON \
    -DWITH_GTK=ON \
    -DWITH_VTK=OFF \
    -DWITH_TBB=OFF \
    -DWITH_1394=OFF \
    -DWITH_OPENEXR=ON \
    -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
    -DCUDA_ARCH_BIN='6.2 7.5' \
    -DCUDA_ARCH_PTX="" \
    -DINSTALL_C_EXAMPLES=ON \
    -DINSTALL_TESTS=OFF \
    -DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
  .. 
$ make
$ make install

ps:WITH_FFMPEG这种是CMakeLists里的变量名,前面加-D才能作为参数进行设置

## 命令详解
///基础设置
-DCMAKE_BUILD_TYPE=Release/Debug //编译类型,选择Release或Debug版
-DOPENCV_EXTRA_MODULES_PATH=/modules //opencv有一个附加库opencv_contrib,里面提供了一系列加速算法,感兴趣的可以去github查看。一般不用装。
-DCMAKE_INSTALL_PREFIX=/usr/local //opencv的安装位置

///OpenCV4没有默认支持pkg-config,要用命令将此项打开。opencv4.pc生成在build/lib/pkgconfig里,需要手动复制到/usr/local/lib/pkgconfig里
-DOPENCV_GENERATE_PKGCONFIG=ON

///编译例程和测试代码
INSTALL_TESTS=ON         //是否编译测试程序
OPENCV_TEST_DATA_PATH=   //测试程序安装路径
BUILD_EXAMPLES=ON        //是否编译例程
BUILD_ANDROID_EXAMPLES   //编译Android例程
INSTALL_C_EXAMPLES       //安装例程
INSTALL_PYTHON_EXAMPLES  //安装例程

///选择设置支持的图片格式
//平时常用的图片格式如jpg,png等opencv是默认支持的,这里主要是选择一些不常见的图片格式,用ON/OFF选择是否支持。各种图片格式的选择可以看后边的参数详解。
-DBUILD_PNG=ON \        
-DBUILD_TIFF=ON \    
-DBUILD_JPEG=ON \
-DBUILD_JASPER=OFF \

///设置需要的第三方库
//1. 使用opengl支持。如果有多个opengl版本,用OpenGL_GL_PREFERENCE设置使用版本。ps:如果不知道版本,可以先运行命令,然后看CMake的报错
//opengl需要gtkglext和gtk支持
-DWITH_OPENGL=ON \
-DOpenGL_GL_PREFERENCE=GLVND \

//2.嵌入式硬件加速库,树莓派官网有一个实现
-DWITH_OPENVX \

//3.Inter的多核多线程支持库
-DWITH_TBB    \

//4.使用CUDA支持,需要设置如下
-DWITH_CUDA=ON \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \	//nvcc编译器位置
-DCUDA_ARCH_BIN='6.2 7.5' \			//设置最低算力支持
-DCUDA_ARCH_PTX="" \
//其他CUDA设置
-DWITH_CUFFT  //Include NVidia Cuda Fast Fourier Transform (FFT) library support
-DWITH_CUBLAS //Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support
//NVIDIA硬解码器
-DWITH_NVCUVID //Include NVidia Video Decoding library support
CUDA最低算力支持是指显卡算力 最低3.0,但现在显卡基本都在7.0以上

2.CMake参数详解

        一下命令来自于OpenCV-3.4.15源代码的CMakeLists文件,如有错误以CMakeLists为准 

/***********编译选项***********/
CMAKE_BUILD_TYPE=Release/Debug 编译类型
CMAKE_INSTALL_PREFIX= 安装位置

//编译例程和测试代码
INSTALL_TESTS=ON 编译测试程序
OPENCV_TEST_DATA_PATH= 测试程序安装路径
BUILD_EXAMPLES=ON 编译例程
BUILD_ANDROID_EXAMPLES 
INSTALL_C_EXAMPLES 安装例程
INSTALL_PYTHON_EXAMPLES 


//选择是自己从源代码编译还是用opencv自带的 ps:以下都是图片格式与相关支持,不包括视频
OPENCV_FORCE_3RDPARTY_BUILD   "Force using 3rdparty code from source" OFF ) //这个开关打开后会不管机器具体情况强制打开以下所有开关,谨慎使用
BUILD_ZLIB               "Build zlib from source"             
BUILD_TIFF               "Build libtiff from source"          
BUILD_JASPER             "Build libjasper from source"        
BUILD_JPEG               "Build libjpeg from source"          
BUILD_PNG                "Build libpng from source"           
BUILD_OPENEXR            "Build openexr from source"          
BUILD_WEBP               "Build WebP from source"             
BUILD_TBB                "Download and build TBB from source" 
BUILD_IPP_IW             "Build IPP IW from source"           
BUILD_ITT                "Build Intel ITT from source"

//选择将要支持的第三方库或驱动,“”里是描述,后面是默认状态。 ps:前提是你电脑里有,否则会从网上下载或不安装
WITH_1394 "Include IEEE1394 support" ON    //苹果火线借口,一个串行标准
WITH_CUDA "Include NVidia Cuda Runtime support" OFF               //打开cuda后会默认打开 WITH_CUFFT , WITH_CUBLAS , WITH_NVCUVID
WITH_EIGEN "Include Eigen2/Eigen3 support" (NOT CV_DISABLE_OPTIMIZATION AND NOT CMAKE_CROSSCOMPILING)    //矩阵计算库
WITH_FFMPEG "Include FFMPEG support" (NOT ANDROID)    //和下边的GSTREAMER都是视频读写库,一般都用ffmpeg,同时NVIDIA的硬解码也可以编译在ffmpeg里。
WITH_GSTREAMER "Include Gstreamer support" ON
WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON
WITH_QUICKTIME "Use QuickTime for Video I/O (OBSOLETE)" OFF
WITH_QTKIT "Use QTKit Video I/O backend" OFF
WITH_V4L "Include Video 4 Linux support" ON    //v4l,连接免驱摄像头用的,就是即插即用那种
WITH_LIBV4L "Use libv4l for Video 4 Linux support" OFF
WITH_DSHOW "Build VideoIO with DirectShow support" ON    //Windows的视频读写接口
WITH_MSMF "Build VideoIO with Media Foundation support" NOT MINGW
WITH_MSMF_DXVA "Enable hardware acceleration in Media Foundation backend" WITH_MSMF
WITH_GTK "Include GTK support" ON    //GTK,Ubuntu桌面所使用的图形库,用此库编译的OpenCV的图形界面会少很多实用有趣的功能,有条件还是用QT
WITH_GTK_2_X "Use GTK version 2" OFF  //编译时系统会自动寻找可用的GTK版本,如非必要,建议选择上一条命令
WITH_JASPER "Include JPEG2K support" ON   
WITH_JPEG "Include JPEG support" ON
WITH_WEBP "Include WebP support" ON
WITH_OPENEXR "Include ILM support via OpenEXR" BUILD_OPENEXR OR NOT CMAKE_CROSSCOMPILING
WITH_OPENGL "Include OpenGL support" OFF    //opengl,一个做图形界面的标准接口,一般是和显卡驱动绑在一起的,apt-get也能安装,但不知道安的是什么
WITH_OPENVX "Include OpenVX support" OFF
WITH_OPENNI "Include OpenNI support" OFF
WITH_OPENNI2 "Include OpenNI2 support" OFF
WITH_PNG "Include PNG support" ON
WITH_TIFF "Include TIFF support" ON
WITH_QT "Build with Qt Backend support" OFF    //QT的OpenCV-HighGUI真的超好用,但是由于QT占用内存空间太大,所以不太适合电脑内存小的,同时QT安装也比较费劲
WITH_WIN32UI "Build with Win32 UI Backend support" ON
WITH_TBB "Include Intel TBB support" OFF    //Intel的一个开源线程管理库,感兴趣的可以看一看
WITH_OPENMP "Include OpenMP support" OFF
WITH_OPENCL "Include OpenCL Runtime support" (NOT ANDROID AND NOT CV_DISABLE_OPTIMIZATION)
WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF
WITH_OPENCL_D3D11_NV "Include NVIDIA OpenCL D3D11 support" WITH_DIRECTX
WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON
WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON
WITH_CSTRIPES "Include C= support" OFF 
WITH_DIRECTX "Include DirectX support" ON
WITH_INTELPERC "Include Intel Perceptual Computing support" OFF
WITH_VA "Include VA support" OFF
WITH_VA_INTEL "Include Intel VA-API/OpenCL support" OFF
WITH_MFX "Include Intel Media SDK support" OFF //英特尔提供的一个视频开发接口,需要inter硬件
WITH_GPHOTO2 "Include gPhoto2 library support" OFF
WITH_PROTOBUF "Enable libprotobuf" ON
WITH_IMGCODEC_HDR "Include HDR support" ON
WITH_IMGCODEC_SUNRASTER "Include SUNRASTER support" ON
WITH_IMGCODEC_PXM "Include PNM (PBM,PGM,PPM) and PAM formats support" ON
WITH_QUIRC "Include library QR-code decoding" ON
WITH_TENGINE "Include Arm Inference Tengine support" OFF
WITH_ONNX "Include Microsoft ONNX Runtime support" OFF //微软提供的一个搭建onnx神经网的开源runtime,需要自己下载安装

WITH_CARBON "Use Carbon for UI instead of Cocoa (OBSOLETE)" OFF
WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" ON
WITH_CPUFEATURES "Use cpufeatures Android library" ON
WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON
WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION)
WITH_HALIDE "Include Halide support" OFF
WITH_INF_ENGINE "Include Intel Inference Engine support" OFF
WITH_NGRAPH "Include nGraph support" WITH_INF_ENGINE
WITH_GDCM "Include DICOM support" OFF
WITH_PVAPI "Include Prosilica GigE support" OFF
WITH_GIGEAPI "Include Smartek GigE support" OFF
WITH_ARAVIS "Include Aravis GigE support" OFF
WITH_PTHREADS_PF "Use pthreads-based parallel_for" ON
WITH_UNICAP "Include Unicap support (GPL)" OFF
WITH_XIMEA "Include XIMEA cameras support" OFF
WITH_XINE "Include Xine support (GPL)" OFF
WITH_CLP "Include Clp support (EPL)" OFF
WITH_GDAL "Include GDAL Support" OFF
WITH_LAPACK "Include Lapack library support" (NOT CV_DISABLE_OPTIMIZATION)
WITH_ITT "Include Intel ITT support" ON 

//opencv编译选项
BUILD_SHARED_LIBS        "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)"       NOT (ANDROID OR APPLE_FRAMEWORK) )
BUILD_opencv_apps        "Build utility applications (used for example to train classifiers)"       (NOT ANDROID AND NOT WINRT) IF (NOT APPLE_FRAMEWORK) )
BUILD_opencv_js          "Build JavaScript bindings by Emscripten"                                  OFF )
BUILD_ANDROID_PROJECTS   "Build Android projects providing .apk files"                              ON  IF ANDROID )
BUILD_ANDROID_EXAMPLES   "Build examples for Android platform"                                      ON  IF ANDROID )
BUILD_DOCS               "Create build rules for OpenCV Documentation"                              OFF  IF (NOT WINRT AND NOT APPLE_FRAMEWORK))
BUILD_EXAMPLES           "Build all examples"                                                       OFF )
BUILD_PACKAGE            "Enables 'make package_source' command"                                    ON  IF NOT WINRT)
BUILD_PERF_TESTS         "Build performance tests"                                                  NOT INSTALL_CREATE_DISTRIB  IF (NOT APPLE_FRAMEWORK) )
BUILD_TESTS              "Build accuracy & regression tests"                                        NOT INSTALL_CREATE_DISTRIB  IF (NOT APPLE_FRAMEWORK) )
BUILD_WITH_DEBUG_INFO    "Include debug info into release binaries ('OFF' means default settings)"  OFF )
BUILD_WITH_STATIC_CRT    "Enables use of statically linked CRT for statically linked OpenCV"        ON IF MSVC )
BUILD_WITH_DYNAMIC_IPP   "Enables dynamic linking of IPP (only for standalone IPP)"                 OFF )
BUILD_FAT_JAVA_LIB       "Create Java wrapper exporting all functions of OpenCV library (requires static build of OpenCV modules)" ANDROID IF NOT BUILD_SHARED_LIBS)
BUILD_ANDROID_SERVICE    "Build OpenCV Manager for Google Play"                                     OFF IF ANDROID )
BUILD_CUDA_STUBS         "Build CUDA modules stubs when no CUDA SDK"                                OFF  IF (NOT APPLE_FRAMEWORK) )
BUILD_JAVA               "Enable Java support"                                                      (ANDROID OR NOT CMAKE_CROSSCOMPILING)  IF (ANDROID OR (NOT APPLE_FRAMEWORK AND NOT WINRT)) )

//opencv安装选项
INSTALL_CREATE_DISTRIB   "Change install rules to build the distribution package"               OFF )
INSTALL_BIN_EXAMPLES     "Install prebuilt examples"                                            WIN32 IF BUILD_EXAMPLES)
INSTALL_C_EXAMPLES       "Install C examples"                                                   OFF )
INSTALL_PYTHON_EXAMPLES  "Install Python examples"                                              OFF )
INSTALL_ANDROID_EXAMPLES "Install Android examples"                                             OFF IF ANDROID )
INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT APPLE_FRAMEWORK AND BUILD_SHARED_LIBS) )
INSTALL_TESTS            "Install accuracy and performance test binaries and test data"         OFF)

//opencv编译设置 (直接Ctrl-C了)
OCV_OPTION(ENABLE_CCACHE              "Use ccache"                                               (UNIX AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Xcode")) )
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers"                                  MSVC IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) )
OCV_OPTION(ENABLE_SOLUTION_FOLDERS    "Solution folder in Visual Studio or in other IDEs"        (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
OCV_OPTION(ENABLE_PROFILING           "Enable profiling in the GCC compiler (Add flags: -g -pg)" OFF  IF CV_GCC )
OCV_OPTION(ENABLE_COVERAGE            "Enable coverage collection with  GCov"                    OFF  IF CV_GCC )
OCV_OPTION(OPENCV_ENABLE_MEMORY_SANITIZER "Better support for memory/address sanitizers"         OFF)
OCV_OPTION(ENABLE_OMIT_FRAME_POINTER  "Enable -fomit-frame-pointer for GCC"                      ON   IF CV_GCC )
OCV_OPTION(ENABLE_POWERPC             "Enable PowerPC for GCC"                                   ON   IF (CV_GCC AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
OCV_OPTION(ENABLE_FAST_MATH           "Enable compiler options for fast math optimizations on FP computations (not recommended)" OFF)
if(NOT IOS AND CMAKE_CROSSCOMPILING)  # Use CPU_BASELINE instead
OCV_OPTION(ENABLE_NEON                "Enable NEON instructions"                                 (NEON OR ANDROID_ARM_NEON OR AARCH64) IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
OCV_OPTION(ENABLE_VFPV3               "Enable VFPv3-D32 instructions"                            OFF  IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
endif()
OCV_OPTION(ENABLE_NOISY_WARNINGS      "Show all warnings even if they are too noisy"             OFF )
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors"                                 OFF )
OCV_OPTION(ANDROID_EXAMPLES_WITH_LIBS "Build binaries of Android examples with native libraries" OFF  IF ANDROID )
OCV_OPTION(ENABLE_IMPL_COLLECTION     "Collect implementation data on function call"             OFF )
OCV_OPTION(ENABLE_INSTRUMENTATION     "Instrument functions to collect calls trace and performance" OFF )
OCV_OPTION(ENABLE_GNU_STL_DEBUG       "Enable GNU STL Debug mode (defines _GLIBCXX_DEBUG)"       OFF IF ((NOT CMAKE_VERSION VERSION_LESS "2.8.11") AND CV_GCC) )
OCV_OPTION(ENABLE_BUILD_HARDENING     "Enable hardening of the resulting binaries (against security attacks, detects memory corruption, etc)" OFF)
OCV_OPTION(ENABLE_LTO                 "Enable Link Time Optimization" OFF IF CV_GCC OR MSVC)
OCV_OPTION(ENABLE_THIN_LTO            "Enable Thin LTO" OFF IF CV_CLANG)
OCV_OPTION(GENERATE_ABI_DESCRIPTOR    "Generate XML file for abi_compliance_checker tool" OFF IF UNIX)
OCV_OPTION(OPENCV_GENERATE_PKGCONFIG  "Generate .pc file for pkg-config build tool (deprecated)" ON IF (UNIX AND NOT MSVC AND NOT IOS AND NOT ANDROID) )
OCV_OPTION(CV_ENABLE_INTRINSICS       "Use intrinsic-based optimized code" ON )
OCV_OPTION(CV_DISABLE_OPTIMIZATION    "Disable explicit optimized code (dispatched code/intrinsics/loop unrolling/etc)" OFF )
OCV_OPTION(CV_TRACE                   "Enable OpenCV code trace" ON)
OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT ANDROID AND NOT APPLE_FRAMEWORK) )
OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)

OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )


4. 查看实际配置结果

        由于各种原因,有些参数会设置失败,所以在运行完cmake命令后,一定要检查一下实际配置情况。实际配置会在cmake命令输出的最后部分。
        以下是一份示例

## cmake结果
查看实际的编译结果,因为各个PC的实际情况不一样,从此处查看实际编译情况
######################################################
General configuration for OpenCV 3.4.15 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2021-09-04T07:37:25Z
    Host:                        Linux 5.4.0-81-generic x86_64
    CMake:                       3.21.0
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (16 files):         + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (6 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (30 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (7 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++11:                       YES
    C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed  
    Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          m pthread /usr/lib/x86_64-linux-gnu/libOpenGL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libGLU.so cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 calib3d core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev dnn features2d flann highgui imgcodecs imgproc ml objdetect photo shape stitching superres ts video videoio videostab
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 java python2 python3 viz
    Applications:                tests perf_tests examples apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI: 
    GTK+:                        YES (ver 2.24.32)
      GThread :                  YES (ver 2.56.4)
      GtkGlExt:                  YES (ver 1.2.0)
    OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libOpenGL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libGLU.so)

  Media I/O: 
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 2.1.0-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES

  Video I/O:
    FFMPEG:                      YES
      avcodec:                   YES (ver 57.107.100)
      avformat:                  YES (ver 57.83.100)
      avutil:                    YES (ver 55.78.100)
      swscale:                   YES (ver 4.8.100)
      avresample:                NO
    libv4l/libv4l2:              NO
    v4l/v4l2:                    linux/videodev2.h

  Parallel framework:            TBB (ver 2020.2 interface 11102)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   YES (ver 11.4, CUFFT CUBLAS)
    NVIDIA GPU arch:             62 75
    NVIDIA PTX archs:

  Python (for build):            /usr/bin/python2.7

  Install to:                    /usr/local
-----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kidecr/Downloads/opencv-3.4.15/opencv-3.4.15/build

如果有问题请一定详细阅读cmake的报错。

OpenCV的CMakeLists写的十分友好,很容易看懂,如果想了解更多,还请阅读CMakeLists.txt

最后附上OpenCV的官方文档连接:OpenCV: OpenCV modules
官方文档编译指导:OpenCV: Installation in Linux
CUDA编译指导:OpenCV: Building OpenCV for Tegra with CUDA

你可能感兴趣的:(opencv,ubuntu,c++,linux)