Skip to content

Instantly share code, notes, and snippets.

@Heavy02011
Last active September 9, 2023 06:30
Show Gist options
  • Save Heavy02011/b92cb9c4869f9ea226d724b6332e2ce4 to your computer and use it in GitHub Desktop.
Save Heavy02011/b92cb9c4869f9ea226d724b6332e2ce4 to your computer and use it in GitHub Desktop.
cmake for compiling OpenCV on Jetson Nano Orin
# cmake_rb2
# https://stackoverflow.com/questions/67694539/opencv-config-with-two-major-python-3-7-3-8
# https://stackoverflow.com/questions/67694539/opencv-config-with-two-major-python-3-7-3-8
# cd :~/opencv/build/python_loader
# pip wheel . --verbose
#-D CMAKE_INSTALL_PREFIX=/usr \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=ON \
-D WITH_OPENMP=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_PROTOBUF=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D OPENCV_PYTHON3_INSTALL_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_opencv_python3=ON \
-D ENABLE_CONTRIB=1 \
-D ENABLE_HEADLESS=1 \
-D BUILD_EXAMPLES=ON ..
(donkey) rainer@ubuntu:~/opencv/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
> -D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
> -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
> -D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
> -D WITH_OPENCL=OFF \
> -D WITH_CUDA=ON \
> -D CUDA_ARCH_BIN=5.3 \
> -D CUDA_ARCH_PTX="" \
> -D WITH_CUDNN=ON \
> -D WITH_CUBLAS=ON \
> -D ENABLE_FAST_MATH=ON \
> -D CUDA_FAST_MATH=ON \
> -D OPENCV_DNN_CUDA=ON \
> -D ENABLE_NEON=ON \
> -D WITH_QT=ON \
> -D WITH_OPENMP=ON \
> -D BUILD_TIFF=ON \
> -D WITH_FFMPEG=ON \
> -D WITH_GSTREAMER=ON \
> -D WITH_TBB=ON \
> -D BUILD_TBB=ON \
> -D BUILD_TESTS=OFF \
> -D WITH_EIGEN=ON \
> -D WITH_V4L=ON \
> -D WITH_LIBV4L=ON \
> -D WITH_PROTOBUF=ON \
> -D OPENCV_ENABLE_NONFREE=ON \
> -D INSTALL_C_EXAMPLES=OFF \
> -D INSTALL_PYTHON_EXAMPLES=ON \
> -D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
> -D OPENCV_PYTHON3_INSTALL_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
> -D OPENCV_GENERATE_PKGCONFIG=ON \
> -D BUILD_opencv_python3=ON \
> -D ENABLE_CONTRIB=1 \
> -D ENABLE_HEADLESS=1 \
> -D BUILD_EXAMPLES=ON ..
-- Detected processor: aarch64
Python 2.7.18
-- Looking for ccache - not found
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3")
Cleaning INTERNAL cached variable: WEBP_LIBRARY
Cleaning INTERNAL cached variable: WEBP_INCLUDE_DIR
-- Found WebP: /home/rainer/miniconda3/envs/donkey/lib/libwebp.so
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.8.0-dev-openjp2-2.5.0
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11")
-- Found OpenEXR: /usr/lib/aarch64-linux-gnu/libIlmImf.so
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
available. Run "cmake --help-policy CMP0072" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
FindOpenGL found both a legacy GL library:
OPENGL_gl_LIBRARY: /usr/lib/aarch64-linux-gnu/libGL.so
and GLVND libraries for OpenGL and GLX:
OPENGL_opengl_LIBRARY: /usr/lib/aarch64-linux-gnu/libOpenGL.so
OPENGL_glx_LIBRARY: /usr/lib/aarch64-linux-gnu/libGLX.so
OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
cmake/OpenCVFindLibsGUI.cmake:66 (find_package)
CMakeLists.txt:755 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
-- CUDA detected: 11.4
-- CUDA: Using CUDA_ARCH_BIN=5.3
-- CUDA NVCC target flags: -gencode;arch=compute_53,code=sm_53;-D_FORCE_INLINES
-- LAPACK(Atlas): LAPACK_LIBRARIES: /usr/lib/aarch64-linux-gnu/liblapack.so;/usr/lib/aarch64-linux-gnu/libcblas.so;/usr/lib/aarch64-linux-gnu/libatlas.so
-- LAPACK(Atlas): Support is enabled.
-- Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE)
-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- Could NOT find Flake8 (missing: FLAKE8_EXECUTABLE)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Checking for module 'gtkglext-1.0'
-- No package 'gtkglext-1.0' found
-- freetype2: YES (ver 23.1.17)
-- harfbuzz: YES (ver 2.6.4)
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Julia not found. Not compiling Julia Bindings.
-- Module opencv_ovis disabled because OGRE3D was not found
-- CERES support is disabled. Ceres Solver for reconstruction API is required.
-- Tesseract: YES (ver 4.1.1)
-- Allocator metrics storage type: 'int'
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Excluding from source files list: modules/imgproc/src/corner.avx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.sse4_1.cpp
-- Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.sse4_1.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/rainer/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out ocl4dnn source code
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_winograd_f63.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_winograd_f63.avx2.cpp
-- Excluding from source files list: modules/features2d/src/fast.avx2.cpp
-- highgui: using builtin backend: QT5
-- CERES support is disabled. Ceres Solver for reconstruction API is required.
-- Building with NVIDIA Optical Flow API 2.0
-- Found 'misc' Python modules from /home/rainer/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/rainer/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/rainer/opencv/modules/gapi/misc/python/package
-- Found 'misc' Python modules from /home/rainer/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/rainer/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/rainer/opencv/modules/gapi/misc/python/package
-- OpenCL samples are skipped: OpenCL SDK is required
-- SYCL/OpenCL samples are skipped: SYCL SDK is required
-- - check configuration of SYCL_DIR/SYCL_ROOT/CMAKE_MODULE_PATH
-- - ensure that right compiler is selected from SYCL SDK (e.g, clang++): CMAKE_CXX_COMPILER=/usr/bin/c++
-- Registered 'check_pylint' target: using /home/rainer/miniconda3/envs/donkey/bin/pylint (ver: 2.16.2), checks: 192
--
-- General configuration for OpenCV 4.8.0-dev =====================================
-- Version control: 1a8d37d
--
-- Extra modules:
-- Location (extra): /home/rainer/opencv_contrib/modules
-- Version control (extra): 9e13469
--
-- Platform:
-- Timestamp: 2023-09-08T20:05:04Z
-- Host: Linux 5.10.120-tegra aarch64
-- CMake: 3.16.3
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: RELEASE
--
-- CPU/HW features:
-- Baseline: NEON FP16
-- required: NEON
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ standard: 11
-- C++ Compiler: /usr/bin/c++ (ver 9.4.0)
-- C++ flags (Release): -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-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 -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 -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fopenmp -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-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 -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 -Wl,--no-undefined
-- Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda-11.4/lib64 -L/usr/lib/aarch64-linux-gnu
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python2 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
-- Disabled: cudacodec world
-- Disabled by dependency: -
-- Unavailable: java julia matlab ovis python3 viz
-- Applications: perf_tests examples apps
-- Documentation: NO
-- Non-free algorithms: YES
--
-- GUI: QT5
-- QT: YES (ver 5.12.8 )
-- QT OpenGL support: YES (Qt5::OpenGL 5.12.8)
-- GTK+: YES (ver 3.24.20)
-- GThread : YES (ver 2.64.6)
-- GtkGlExt: NO
-- OpenGL support: YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
-- JPEG: /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
-- WEBP: /home/rainer/miniconda3/envs/donkey/lib/libwebp.so (ver encoder: 0x020f)
-- PNG: /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.37)
-- TIFF: build (ver 42 - 4.2.0)
-- JPEG 2000: build (ver 2.5.0)
-- 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_3)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- DC1394: YES (2.2.5)
-- FFMPEG: YES
-- avcodec: YES (58.54.100)
-- avformat: YES (58.29.100)
-- avutil: YES (56.31.100)
-- swscale: YES (5.5.100)
-- avresample: YES (4.0.0)
-- GStreamer: YES (1.16.3)
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: TBB (ver 2020.2 interface 11102)
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Lapack: YES (/usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so)
-- Default DNN backend: DNN_BACKEND_OPENCV
-- Eigen: YES (ver 3.3.7)
-- Custom HAL: YES (carotene (ver 0.0.1))
-- Protobuf: build (3.19.1)
-- Flatbuffers: builtin/3rdparty (23.5.9)
--
-- NVIDIA CUDA: YES (ver 11.4, CUFFT CUBLAS FAST_MATH)
-- NVIDIA GPU arch: 53
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 8.6.0)
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.18)
-- Libraries: /usr/lib/aarch64-linux-gnu/libpython2.7.so (ver 2.7.18)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.5)
-- install path: lib/python2.7/dist-packages/cv2/python-2.7
--
-- Python 3:
-- Interpreter: /home/rainer/miniconda3/envs/donkey/bin/python3 (ver 3.8.17)
-- Libraries: NO
-- numpy: /home/rainer/miniconda3/envs/donkey/lib/python3.8/site-packages/numpy/core/include (ver 1.24.3)
-- install path: -
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: NO
-- Java: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /home/rainer/miniconda3/envs/donkey
-- -----------------------------------------------------------------
--
-- Configuring done
CMake Warning at cmake/OpenCVUtils.cmake:1560 (add_library):
Cannot generate a safe runtime search path for target opencv_imgcodecs
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libpng16.so.16] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
/home/rainer/miniconda3/envs/donkey/lib
runtime library [libz.so.1] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
/home/rainer/miniconda3/envs/donkey/lib
Some of these libraries may not be found correctly.
Call Stack (most recent call first):
cmake/OpenCVModule.cmake:989 (ocv_add_library)
cmake/OpenCVModule.cmake:905 (_ocv_create_module)
modules/imgcodecs/CMakeLists.txt:168 (ocv_create_module)
-- Generating done
-- Build files have been written to: /home/rainer/opencv/build
# stackoverflow https://stackoverflow.com/questions/70334087/how-to-build-opencv-from-source-with-python-binding
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_CUDA=ON \
-D BUILD_opencv_cudacodec=OFF \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D WITH_GSTREAMER=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv_contrib/modules \
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_EXAMPLES=ON ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment