Building OpenCv on Jetson Nano B01

Hi all,
I need to compile OpenCV for Python 3.9 on Jetson Nano (ARM) to be able to get gstreamer support, which isn’t available from the PyPi wheel.

I’ve successfully build python 3.9.5 with static and shared libs and installed in /opt/python39x64

My problem is, that no matter what I do, cmake-gui claims not to find Python3 and also not building the cv2.so, even when setting the resp. flags:

and the configure output is:

Detected processor: aarch64
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") 
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.3-pre-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11") 
CUDA detected: 10.2
CUDA: Using CUDA_ARCH_BIN=5.3
CUDA NVCC target flags: -gencode;arch=compute_53,code=sm_53;-D_FORCE_INLINES
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY) 
A library with BLAS API found.
A library with LAPACK API found.
The imported target "vtkRenderingPythonTkWidgets" references the file
   "/usr/lib/aarch64-linux-gnu/libvtkRenderingPythonTkWidgets.so"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

The imported target "vtk" references the file
   "/usr/bin/vtk"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.

Found VTK 6.3.0 (/usr/lib/cmake/vtk-6.3/UseVTK.cmake)
OpenCV Python: during development append to PYTHONPATH: /home/phoenix/Sources/opencv/build/python_loader
freetype2:   YES (ver 21.0.15)
harfbuzz:    YES (ver 1.7.2)
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
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Glog/Gflags
Checking for module 'tesseract'
  No package 'tesseract' found
Tesseract:   NO
Processing WORLD modules...
    module opencv_cudev...
    module opencv_core...
Allocator metrics storage type: 'int'
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.sse2.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.sse3.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.ssse3.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.sse4_1.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.sse4_2.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.avx.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.avx2.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin128.avx512_skx.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin256.avx2.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin256.avx512_skx.cpp
Excluding from source files list: <BUILD>/modules/world/test/test_intrin512.avx512_skx.cpp
    module opencv_cudaarithm...
    module opencv_flann...
    module opencv_hdf...
HDF5: Using hdf5 compiler wrapper to determine C configuration
    module opencv_imgproc...
    module opencv_intensity_transform...
    module opencv_ml...
    module opencv_phase_unwrapping...
    module opencv_plot...
    module opencv_quality...
    module opencv_reg...
    module opencv_surface_matching...
    module opencv_viz...
    module opencv_alphamat...
    module opencv_cudafilters...
    module opencv_cudaimgproc...
    module opencv_cudawarping...
    module opencv_dnn...
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/phoenix/Sources/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
    module opencv_dnn_superres...
    module opencv_features2d...
    module opencv_freetype...
    module opencv_fuzzy...
    module opencv_hfs...
    module opencv_imgcodecs...
    module opencv_line_descriptor...
    module opencv_photo...
    module opencv_saliency...
    module opencv_text...
    module opencv_videoio...
    module opencv_wechat_qrcode...
    module opencv_xphoto...
    module opencv_barcode...
    module opencv_calib3d...
    module opencv_cudacodec...
    module opencv_cudafeatures2d...
    module opencv_cudastereo...
    module opencv_datasets...
    module opencv_highgui...
highgui: using builtin backend: GTK3
    module opencv_mcc...
    module opencv_objdetect...
    module opencv_rapid...
    module opencv_rgbd...
    module opencv_shape...
    module opencv_structured_light...
    module opencv_video...
    module opencv_xfeatures2d...
    module opencv_ximgproc...
    module opencv_xobjdetect...
    module opencv_aruco...
    module opencv_bgsegm...
    module opencv_bioinspired...
    module opencv_ccalib...
    module opencv_cudabgsegm...
    module opencv_cudalegacy...
    module opencv_cudaobjdetect...
    module opencv_dnn_objdetect...
    module opencv_dpm...
    module opencv_face...
    module opencv_optflow...
    module opencv_stitching...
    module opencv_tracking...
    module opencv_cudaoptflow...
Building with NVIDIA Optical Flow API 2.0
    module opencv_stereo...
    module opencv_superres...
    module opencv_videostab...
Processing WORLD modules... DONE
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.sse4_1.cpp
Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
Excluding from source files list: modules/imgproc/src/resize.sse4_1.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.avx.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.avx2.cpp
Excluding from source files list: <BUILD>/modules/world/layers/layers_common.avx512_skx.cpp
Excluding from source files list: modules/features2d/src/fast.avx2.cpp

General configuration for OpenCV 4.5.3-pre =====================================
  Version control:               4.5.2-267-gc95a56450d

  Extra modules:
    Location (extra):            /home/phoenix/Sources/opencv/opencv_contrib/modules
    Version control (extra):     4.5.2-267-gc95a56450d

  Platform:
    Timestamp:                   2021-06-26T11:20:30Z
    Host:                        Linux 4.9.201-tegra aarch64
    CMake:                       3.10.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    NEON FP16

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -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 cudart_static dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy 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 shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab viz wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    gapi java_bindings_generator python_tests
    Disabled by dependency:      -
    Unavailable:                 cvv java julia matlab ovis python3 python3 sfm
    Applications:                tests apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI: 
    GTK+:                        YES (ver 3.22.30)
      GThread :                  YES (ver 2.56.4)
      GtkGlExt:                  YES (ver 1.2.0)
    OpenGL support:              NO
    VTK support:                 YES (ver 6.3.0)

  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:                        /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0x020e)
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
    TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    GDAL:                        YES (/usr/lib/libgdal.so)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    FFMPEG:                      YES
      avcodec:                   YES (57.107.100)
      avformat:                  YES (57.83.100)
      avutil:                    YES (55.78.100)
      swscale:                   YES (4.8.100)
      avresample:                YES (3.7.0)
    GStreamer:                   YES (1.14.5)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            pthreads

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       YES (ver 3.3.4)
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS)
    NVIDIA GPU arch:             53
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.0.0)

  OpenCL:                        YES (no extra features)
    Include path:                /home/phoenix/Sources/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.17)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython2.7.so (ver 2.7.17)
    numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python2.7/dist-packages/cv2/python-2.7

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

  Install to:                    /usr/local
-----------------------------------------------------------------

Configuring done

I’ve tried already several tutorials, even installed the python3.9-dev, lib…blabla via deadsnakes/ppa, but nothing makes cmake change it’s mind. Does anyone have an idea how to just build the py-lib?

this does not look like the very 1st cmake run on your box, more like the 2nd or 3rd attempt (try to delete build/CmakeCache.txt and re-run)

definitely not, where cmake will look for it.

  • cleanup
  • run cmake-gui again
  • type PYTHON3_ into the search box
  • fill in pathes to your custom location
  • configure / generate

Thanks, I tried this ( well actually I’m doing it like this the whole weekend already)

I can’t use the search box before the first configure step, as the window is empty. After that step, it find parts of the systems Python3.6. It’s still disabled thou. The important part at the beginning of the output:

Detected processor: aarch64
Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.17", minimum required is "2.7") 
Found PythonLibs: /usr/lib/aarch64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.17") 
Found PythonInterp: /usr/bin/python3 (found suitable version "3.6.9", minimum required is "3.2") 
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) (Required is exact version "3.6.9")
Looking for ccache - not found

I under stand that cmake won’t find my installation at that location, but that’s the nature of being able to install software as one likes for the past 40 years - and it doesn’t actually even have to, as I give it all the information where to find the installation manually. However after the suggested steps, like before, it claims that python3 is unavailable.
Does your remark, that this is the 2nd or 3rd run mean, that after Python3 is not found properly at first run, no matter what I change in the settings, it will stay disabled? In that case, I have to find a way set these somewhere in the cmake, so it’s available on first run.

Edit: I added this these path to my python installation temporarily in the console via export and started cmake-gui from there in the hope the PATH would be exposed. It didn’t work either

you need the dev version of it
(or you still did not fill out ALL nessecary fields)
(opencv’s python wrappers need access to the python headers & lib (same for numpy))

Is the Jetson Nano by Nvidia similar to Raspberry Pi Zero by the Raspberry Pi Foundation in terms of board and processor specs? If it is, I installed OpenCV without compilation in this article:

Installing OpenCV on Raspberry Pi Zero

I have no idea how GStreamer works. But if you’re trying to install OpenCV on the Jetson Nano without compilation, then the above link may give you some commands / ideas to complete installation.

I know, I have the dev version of 3.9.5 (including all python headers, all numpy headers and the .so, all build on this system for arm. The error message is coming on first run when it only finds 3.6. But 3.6 is end-of-life and goes deprecated on 2021-12, therefore I don’t install the dev for this and need it to work on 3.9.5 to match the code on other workstations.

The picamera provides a pure Python interface to the Raspberry Pi camera. I doubt it will be able to access the dual IMX219 CSI cameras on Nano, but i’ll give it a try. OpenCV without gstreamer is also not able to extract images from it.

I’m currently considering to do it the C++ way instead as the cmake seems to be broken in individual environments - I mean it’s still using 2.7 as default, in 2021.

are you sure “python39x64” is suitable for ARM? sounds like intel/AMD x64… weird in any case. I hope that’s just weird naming on your part, and not actually an intel/AMD x64 build.

can your self-built python binaries be executed at all, without involving opencv?

yes, that’s a “weird” naming convention from my part, as I work mainly on windows with different versions 2.7/3.7/3.8 in 32 and 64 bits ( at least back than) and used the same name as always to tell them apart. This installation is compiled from source on the Jetson and works like a charm. I was working with the PyPi version of OpenCV in Jupyter with it until I realized that the gstreamer is missing.

There’s a lot of problems you’re trying to solve and will take time to do it one by one. Python should be easier to deal with than C++. There’s got to be repositories out there for Jetson Nano which is what you’re looking for. Searching is the hard part. Also, the article with the commands I posted works for Debian based systems like Ubuntu. Not sure if it will work for your distro.

Thanks for the suggestion and sorry for the late response. I’m not going to waste anymore time in solving this.
I’ve created a c++ application which is now grabbing the stereo images from the camera and writing them to disk. For now I will just read in the still images into python and do the reconstruction there. Later I might use embedded python, I did that already in my master thesis back than, to call at least some parts of the scripts on live images - the Nano isn’t really suitable for live processing of 8K anyway.
I leave this open however, in case someone finds a solution. I found several other threads from ppl having problems compiling the pyBinding, so I am at least not the only one.