Ubuntu 18.04源码编译opencv3.4.10

文章目录

  • 前言
  • 一、开发部署环境
  • 二、安装步骤
    • 1.安装编译环境所需依赖包
    • 2. 安装Python环境及依赖包
    • 3.make&make install opencv
    • 4. 测试opencv是否编译成功
    • 5. 附上cmake配置文件
    • 6.OpenCV 3.4.10的Cmake选项默认已打开选项
  • 总结


前言

在Ubuntu 18.04环境下源码编译OpenCV,与Qt5、FFMpeg和X264等配合使用。


提示:以下是本篇文章正文内容,下面案例可供参考

一、开发部署环境

开发环境 软件版本
PC系统版本 Ubuntu 18.04LTS
OpenCV版本 3.4.10
Python版本 Python3.7
numpy版本 1.16.3

二、安装步骤

1.安装编译环境所需依赖包

#安装编译所需依赖包
 user@admin-machine:~$ sudo apt-get update
 user@admin-machine:~$ sudo apt-get install build-essential
 user@admin-machine:~$ sudo apt install software-properties-common
 user@admin-machine:~$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
 user@admin-machine:~$ sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
 user@admin-machine:~$ sudo apt update
 user@admin-machine:~$ sudo apt install libjasper1 libjasper-dev
 user@admin-machine:~$ sudo apt-get install  libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
user@admin-machine:~$ sudo apt-get install -y libgstreamer1.0-0 \
                      gstreamer1.0-plugins-base \
                      gstreamer1.0-plugins-good \
                      gstreamer1.0-plugins-bad \
                      gstreamer1.0-plugins-ugly \
                      gstreamer1.0-libav \
                      gstreamer1.0-doc \
                      gstreamer1.0-tools \
                      libgstreamer1.0-dev \
                      libgstreamer-plugins-base1.0-dev

2. 安装Python环境及依赖包

  • 安装Python3.7
user@admin-machine:~$ sudo apt update #检查可更新文件
user@admin-machine:~$ sudo apt install software-properties-common  #安装可添加源的工具
user@admin-machine:~$ sudo add-apt-repository ppa:deadsnakes/ppa #添加源,否则会无法找到python3.7-dev软件包
user@admin-machine:~$ sudo apt install python3.7-dev -y #安装python3.7
  • 配置Python3.7环境
#查看路径python,python3.7路径
user@admin-machine:~$ which python python3.7
/usr/bin/python
/usr/bin/python3.7
user@admin-machine:~$ sudo rm /usr/bin/python
user@admin-machine:~$ sudo rm /usr/bin/python3
#创建python3.7软连接到python&Python3
user@admin-machine:~$ sudo ln -s /usr/bin/python3.7 /usr/bin/python
user@admin-machine:~$ sudo ln -s /usr/bin/python3.7 /usr/bin/python3
  • 安装pip包和numpy
user@admin-machine:~$ sudo apt-get install python3-pip -y
user@admin-machine:~$ sudo python3 -m pip install --upgrade --force-reinstall pip
user@admin-machine:~$ pip3 -V
pip 21.0.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

user@admin-machine:~$ pip3 install numpy==1.16.3 -i https://pypi.tuna.tsinghua.edu.cn/simple

user@admin-machine:~$ pip3 show numpy
Name: numpy
Version: 1.16.3
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /home/user/.local/lib/python3.7/site-packages
Requires: 
Required-by: 

  • 测试numpy是否可用
user@admin-machine:~$ python3
>>> import numpy
>>> numpy.__version__
'1.16.3'
>>> 

3.make&make install opencv

  • 配置cmake
user@admin-machine:~$ cd /opencv/opencv-3.4.10/$ 
user@admin-machine:~$ sudo makedir release
user@admin-machine:~$ cd release
user@admin-machine:~$ cmake -D CMAKE_INSTALL_PREFIX=/home/user/opencv/opencv-3.4.10/release/install -D BUILD_opencv_python3=yes -D BUILD_opencv_python2=no -D \
PYTHON3_EXECUTABLE=/usr/bin/python3.7m -D \
PYTHON3_INCLUDE_DIR=/usr/include/python3.7m -D \
PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so -D \
PYTHON3_NUMPY_INCLUDE_DIRS=/home/user/.local/lib/python3.7/site-packages/numpy/core/include -D \
PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages -D \
PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.7m ..
  • 打印以下内容

```bash
-- 
-- General configuration for OpenCV 3.4.10 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Timestamp:                   2021-04-13T07:42:18Z
--     Host:                        Linux 5.4.0-66-generic x86_64
--     CMake:                       3.10.2
--     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 (15 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 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (6 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 -Winit-self -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 -Winit-self -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 -Winit-self -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 -Winit-self -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:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc java ml objdetect photo python3 shape stitching superres ts video videoio videostab
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev js python2 viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
--     GTK+:                        YES (ver 2.24.32)
--       GThread :                  YES (ver 2.56.4)
--       GtkGlExt:                  NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (ver 2.2.5)
--     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
--     GStreamer:                   NO
--     libv4l/libv4l2:              NO
--     v4l/v4l2:                    linux/videodev2.h
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/user/opencv/opencv-3.4.10/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3.7m (ver 3.7.10)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.7m.so (ver 3.7.10)
--     numpy:                       /home/user/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.16.3)
--     install path:                /usr/lib/python3/dist-packages/cv2/python-3.7
-- 
--   Python (for build):            /usr/bin/python3.7m
-- 
--   Java:                          
--     ant:                         /usr/bin/ant (ver 1.10.5)
--     JNI:                         /opt/jvm/jdk-15.0.1/include /opt/jvm/jdk-15.0.1/include/linux /opt/jvm/jdk-15.0.1/include
--     Java wrappers:               YES
--     Java tests:                  YES
-- 
--   Install to:                    /home/user/opencv/opencv-3.4.10/release/install
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/opencv/opencv-3.4.10/release
  • 编译
user@admin-machine:~$ sudo make -j4
...
BUILD SUCCESSFUL
Total time: 4 seconds
[100%] Built target opencv_test_java
[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so
[100%] Built target opencv_python3

  • 安装OpenCV
user@admin-machine:~$ sudo make install -j4
...
-- Installing: /home/user/opencv/opencv-3.4.10/release/install/bin/opencv_traincascade
-- Set runtime path of "/home/user/opencv/opencv-3.4.10/release/install/bin/opencv_traincascade" to "/home/user/opencv/opencv-3.4.10/release/install/lib"
-- Installing: /home/user/opencv/opencv-3.4.10/release/install/bin/opencv_createsamples
-- Set runtime path of "/home/user/opencv/opencv-3.4.10/release/install/bin/opencv_createsamples" to "/home/user/opencv/opencv-3.4.10/release/install/lib"
-- Installing: /home/user/opencv/opencv-3.4.10/release/install/bin/opencv_annotation
-- Set runtime path of "/home/user/opencv/opencv-3.4.10/release/install/bin/opencv_annotation" to "/home/user/opencv/opencv-3.4.10/release/install/lib"
-- Installing: /home/user/opencv/opencv-3.4.10/release/install/bin/opencv_visualisation
-- Set runtime path of "/home/user/opencv/opencv-3.4.10/release/install/bin/opencv_visualisation" to "/home/user/opencv/opencv-3.4.10/release/install/lib"
-- Installing: /home/user/opencv/opencv-3.4.10/release/install/bin/opencv_interactive-calibration
-- Set runtime path of "/home/user/opencv/opencv-3.4.10/release/install/bin/opencv_interactive-calibration" to "/home/user/opencv/opencv-3.4.10/release/install/lib"
-- Installing: /home/user/opencv/opencv-3.4.10/release/install/bin/opencv_version
-- Set runtime path of "/home/user/opencv/opencv-3.4.10/release/install/bin/opencv_version" to "/home/user/opencv/opencv-3.4.10/release/install/lib"

  • 添加动态库加载路径
user@admin-machine:~$ sudo vim /etc/ld.so.conf.d/opencv.conf
/home/user/opencv/opencv-3.4.10/release/install/lib

vim中输入:wq指令保存并退出,随后运行sudo ldconfig激活生效。

  • 运行sudo vim /etc/bash.bashrc 在最后一行添加如下
PKG_CONFIG_PATH=/home/user/opencv/opencv-3.4.10/release/install/lib/pkgconfig:$PKG_CONFIG_PATH
 export PKG_CONFIG_PATH

vim中输入:wq指令保存并退出,随后运行source ~/.bashrc激活生效。

  • 重启PC
user@admin-machine:~$ sudo reboot
  • 验证OpenCV动态链接库是否生效,若出现以下路径,则表明动态链接库生效
user@admin-machine:~$ pkg-config --libs --cflags opencv
-I/home/user/opencv/opencv-3.4.10/release/install/include/opencv -I/home/user/opencv/opencv-3.4.10/release/install/include -L/home/user/opencv/opencv-3.4.10/release/install/lib -lopencv_dnn -lopencv_highgui -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_videoio -lopencv_imgcodecs -lopencv_features2d -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core

4. 测试opencv是否编译成功

打开/home/user/opencv/opencv-3.4.10/samples/cpp/example_cmake目录,修改CMakeLists.txt,指定OpenCVConfig.cmake opencv-config.cmake的安装路径,否则cmake会报错。
执行:

user@admin-machine:~$ sudo vim CMakeLists.txt
# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(opencv_example_project)

# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
#新增以下行,指定OpenCV__DIR的路径
set(OpenCV_DIR /home/user/opencv/opencv-3.4.10/release/install/share/OpenCV)
find_package(OpenCV REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS})
user@admin-machine:~$ cmake .
user@admin-machine:~$ make
user@admin-machine:~$ ./opencv_example

执行完成后会弹出一个窗口,并实时显示电脑USB摄像头拍到的画面。
Ubuntu 18.04源码编译opencv3.4.10_第1张图片

user@admin-machine:~$ python3
>>> import cv2
>>> cv2.__version__
'3.4.10'

5. 附上cmake配置文件

(以下命令是在AIO-3399ProC开发板上执行的,执行前先编译nasm,x.264及ffmpeg,具体步骤参考此文:《解决(ARM64-ARMV8)嵌入式Linux系统下X264编码提示:libx264 :use cpu capability none!》)

user@admin-machine:~$ sudo cmake \
-D BUILD_opencv_python3=yes -D BUILD_opencv_python2=no \
-D PYTHON3_EXECUTABLE=/usr/bin/python3.7m \
-D PYTHON3_INCLUDE_DIR=/usr/include/python3.7m \
-D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/home/user/.local/lib/python3.7/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.7m \
-D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/firefly/opencv-3.4.10/release/install \
-D BUILD_JPEG=ON -D BUILD_PNG=ON -D BUILD_ZLIB=ON \
-D ENABLE_CXX11=ON \
-D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D WITH_GTK=ON -D WITH_GTK_2_X=ON -D WITH_OPENCL=ON -D WITH_OPENGL=ON -D WITH_OPENMP=ON -D WITH_PNG=ON \
-D WITH_QT=ON \
-D Qt5Concurrent_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5Concurrent \
-D Qt5Core_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5Core \
-D Qt5Gui_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5Gui \
-D Qt5OpenGL_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5OpenGL \
-D Qt5Test_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5Test \
-D Qt5Widgets_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5Widgets \
-D Qt5_DIR=/opt/Qt5.12.2/5.12.2/gcc_64/lib/cmake/Qt5 ..

执行后打印以下日志:

-- General configuration for OpenCV 3.4.10 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Timestamp:                   2021-04-19T06:30:02Z
--     Host:                        Linux 4.4.194 aarch64
--     CMake:                       3.10.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    NEON FP16
--       required:                  NEON
--       disabled:                  VFPV3
-- 
--   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 -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -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 -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -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 -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fopenmp -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 -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fopenmp -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:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc ml objdetect photo python3 shape stitching superres ts video videoio videostab
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java js python2 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:                  NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        build-libjpeg-turbo (ver 2.0.4-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
--     JPEG 2000:                   /usr/lib/aarch64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2_2)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (ver 2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 58.35.100)
--       avformat:                  YES (ver 58.20.100)
--       avutil:                    YES (ver 56.22.100)
--       swscale:                   YES (ver 5.3.100)
--       avresample:                YES (ver 4.0.0)
--     GStreamer:                   YES
--       base:                      YES (ver 1.14.5)
--       video:                     YES (ver 1.14.5)
--       app:                       YES (ver 1.14.5)
--       riff:                      YES (ver 1.14.5)
--       pbutils:                   YES (ver 1.14.5)
--     libv4l/libv4l2:              NO
--     v4l/v4l2:                    linux/videodev2.h
-- 
--   Parallel framework:            OpenMP
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/firefly/opencv-3.4.10/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3.7m (ver 3.7.10)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.7m.so (ver 3.7.10)
--     numpy:                       /home/user/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.16.3)
--     install path:                /usr/lib/python3/dist-packages/cv2/python-3.7
-- 
--   Python (for build):            /usr/bin/python3.7m
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /home/firefly/opencv-3.4.10/release/install
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/firefly/opencv-3.4.10/release

6.OpenCV 3.4.10的Cmake选项默认已打开选项

#opencv 3.4.10 cmake默认已打开选项
BUILD_IPP_IW
BUILD_ITT
BUILD_JAVA
BUILD_PACKAGE
BUILD_PERF_TESTS
BUILD_PROTOBUF
BUILD_SHARED_LIBS
BUILD_TESTS
BUILD_opencv_apps
BUILD_opencv_calib3d
BUILD_opencv_core
BUILD_opencv_dnn
BUILD_opencv_features2d
BUILD_opencv_flann
BUILD_opencv_gapi
BUILD_opencv_highgui
BUILD_opencv_imgcodecs
BUILD_opencv_imgprroc
BUILD_opencv_java
BUILD_opencv_java_bindings_generator
BUILD_opencv_ml
BUILD_opencv_objdetect
BUILD_opencv_photo
BUILD_opencv_python2
BUILD_opencv_python3
BUILD_opencv_python_bindlings_generator
BUILD_opencv_python_tests
BUILD_opencv_sitching
BUILD_opencv_ts
BUILD_opencv_video
BUILD_opencv_videoio

CV_ENABLE_INTRINSICS
CV_TRACE

ENABLE_CCACHE
ENABLE_OMIT_FRAME_POINTER
ENABLE_PIC

OPENCL_FOUND
OPENCV_DNN_OPENCL
OPENCV_ENABLE_ALLOCATOR_STATS
OPENCV_ENABLE_ATOMIC_LONG_LONG
OPENCV_ENABLE_MEMALIGN
OPENCV_GENERATE_PKGCONFIG
OPENCV_GENERATE_SETUPVARS
WITH_1394
WITH_ADE
WITH_EIGEN
WITH_FFMPEG
WITH_GSTREAMER
WITH_GTK
WITH_IMGCODEC_HDR
WITH_IMGCODEC_PFM
WITH_IMGCODEC_PXM
WITH_IMGCODEC_SUNRASTER
WITH_IPP
WITH_ITT
WITH_JASPER
WITH_JPEG
WITH_LAPACK
WITH_OPENCL
WITH_OPENCLAMDBLAS
WITH_OPENCLAMDFFT
WITH_OPENEXR
WITH_OPENJPEG
WITH_PNG
WITH_PROTOBUF
WITH_PTHREADS_PF
WITH_QUIRC
WITH_TIFF
WITH_V4L
WITH_VTK
WITH_WEBP

总结

OpenCV源码编译过程繁琐,之前用Cmake-gui工具编译一直出错,还是在命令行中手动配置后编译方正常通过。
部分参考文章:

  • Ubuntu18.04交叉编译OpenCV3.4.9和QT5.12.2至ARM64位平台firefly-RK3399(一)
  • OpenCV Install 3.4.10
  • Ubuntu18.04中安装python3.7解决sudo : pip: 找不到命令
  • How to build opencv-python如何本地编译OpenCV的Python版本
  • Ubuntu 20.04 从源码编译并配置OpenCV 4.4.0 以及python 3.8支持
  • Ubuntu18.04 源码编译OpenCV4.1.1
  • Ubuntu18.04下安装OpenCv依赖包libjasper-dev无法安装的问题
  • 解决编译opencv时,卡在IPPICV: Download: ippicv_2020_lnx_intel64_20191018_general.tgz
  • OpenCV找不到config.cmake(简单直接的解决方法):Could not find a package configuration file provided by “OpenCV“
  • 海思交叉编译opencv4(以opencv400为例)

你可能感兴趣的:(opencv,ubuntu,视频处理)