Unable to install OpenCV 3.2 with JetPack 4.6.3 in AGX Xavier

I am using ROS Melodic (Ubuntu 18.04 LTS), so I used JetPack v4.6.3 to get started with the AGX Xavier device. While compiling a ROS package, I got the OpenCV mismatch error as shown below:

  CMake Error at CMakeLists.txt:31 (find_package):
    Could not find a configuration file for package "OpenCV" that is compatible
    with requested version "3".
  
    The following configuration files were considered but not accepted:
  
      /usr/lib/aarch64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake, version: 4.1.1
  
  
  
  -- Configuring incomplete, errors occurred!

I looked at the OpenCV package installed on AGX Xavier and found two versions as shown below:

ravi@ubuntu:~/ros_ws$ dpkg -l | grep libopencv
ii  libopencv                                             4.1.1-2-gd5a58aa75                         arm64        Open Computer Vision Library
ii  libopencv-calib3d3.2:arm64                            3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Camera Calibration library
ii  libopencv-core3.2:arm64                               3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision core library
ii  libopencv-dev                                         4.1.1-2-gd5a58aa75                         arm64        Development files for Open Source Computer Vision Library
ii  libopencv-features2d3.2:arm64                         3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Feature Detection and Descriptor Extraction library
ii  libopencv-flann3.2:arm64                              3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Clustering and Search in Multi-Dimensional spaces library
ii  libopencv-highgui3.2:arm64                            3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision High-level GUI and Media I/O library
ii  libopencv-imgcodecs3.2:arm64                          3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Image Codecs library
ii  libopencv-imgproc3.2:arm64                            3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Image Processing library
ii  libopencv-ml3.2:arm64                                 3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Machine Learning library
ii  libopencv-python                                      4.1.1-2-gd5a58aa75                         arm64        Python bindings for Open Source Computer Vision Library
ii  libopencv-samples                                     4.1.1-2-gd5a58aa75                         arm64        Samples for Open Source Computer Vision Library
ii  libopencv-videoio3.2:arm64                            3.2.0+dfsg-4ubuntu0.1                      arm64        computer vision Video I/O library

You can see there are two versions, i.e., 3.2.0 installed by ROS, and 4.1.1 installed by JetPack. Therefore, in order to fix my issue, I tried installing OpenCV 3.2.0 from source. I quickly jumped into jetsonhacks/buildOpenCVXavier repository. I set the OPENCV_VERSION=3.2.0 and executed the script. Unfortunately, the compilation did not work. Below is the errors snippet:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
    linked by target "opencv_cudev" in directory /home/ravi/opencv/modules/cudev
    linked by target "opencv_cudev" in directory /home/ravi/opencv/modules/cudev
    linked by target "opencv_test_cudev" in directory /home/ravi/opencv/modules/cudev/test
    linked by target "opencv_test_core" in directory /home/ravi/opencv/modules/core
    linked by target "opencv_core" in directory /home/ravi/opencv/modules/core
    linked by target "opencv_core" in directory /home/ravi/opencv/modules/core
    linked by target "opencv_perf_core" in directory /home/ravi/opencv/modules/core
...

The logs are really long. So I posted them to Pastebin to keep this post shorter and cleaner.

Any workaround, please.

Thank you

Hi,
There is a script from a contributor and yo may give it a try:
GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano

You may also refer to:
https://developer.nvidia.com/blog/accelerating-ai-modules-for-ros-and-ros-2-on-jetson/

Hello @DaneLLL

Thank you very much for your kind support. I tried mdegans/nano_build_opencv for installing version 3.2.0, but got exactly the same error as mentioned in my logs above.

Below is the error snippet:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
    linked by target "opencv_cudev" in directory /tmp/build_opencv/opencv/modules/cudev
    linked by target "opencv_cudev" in directory /tmp/build_opencv/opencv/modules/cudev
    linked by target "opencv_core" in directory /tmp/build_opencv/opencv/modules/core
    linked by target "opencv_core" in directory /tmp/build_opencv/opencv/modules/core
    linked by target "opencv_cudaarithm" in directory /tmp/build_opencv/opencv/modules/cudaarithm
    linked by target "opencv_cudaarithm" in directory /tmp/build_opencv/opencv/modules/cudaarithm
    linked by target "opencv_flann" in directory /tmp/build_opencv/opencv/modules/flann

Any workaround, please.

Thank you again

Next, I tried installing OpenCV 3.4.3 as 3.2.0 failed. Unfortunately, this one showed another error nvcc fatal : Unsupported gpu architecture 'compute_87'. Below is more information:

/tmp/build_opencv/opencv/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp: In member function 'void HaarFeature64::getRect(Ncv32u*, Ncv32u*, Ncv32u*, Ncv32u*)':
/tmp/build_opencv/opencv/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:102:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         NcvRect8u tmpRect = *(NcvRect8u*)(&this->_ui2.x);
                                                        ^
/tmp/build_opencv/opencv/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:102:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
[ 30%] Built target pch_Generate_opencv_ximgproc
[ 30%] Built target pch_Generate_opencv_bgsegm
[ 30%] Built target pch_Generate_opencv_aruco
[ 30%] Built target pch_Generate_opencv_xfeatures2d
[ 30%] Built target pch_Generate_opencv_optflow
[ 30%] Built target pch_Generate_opencv_stitching
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
[  1%] Built target gen-pkgconfig
[  3%] Built target libjasper
[  8%] Built target IlmImf
[ 14%] Built target libprotobuf
[ 17%] Built target carotene_objs
[ 18%] Built target tegra_hal
[ 18%] Built target opencv_cudev
[ 18%] Built target opencv_core_pch_dephelp
[ 18%] Built target pch_Generate_opencv_core
[ 18%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o
nvcc fatal   : Unsupported gpu architecture 'compute_87'
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.RELEASE.cmake:221 (message):
  Error generating
  /tmp/build_opencv/opencv/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o

Hi,
Looks like the previous version does not support Xavier GPU. We would suggest use later version of OpenCV.

For a try you can grep compute_ to find out where the architectures are defined, and then add compute_87. This is not recommended but you may give it a try.

Thank you very much.

The reason why I chose OpenCV 3.2.0 is that ROS Melodic comes with this OpenCV.

My quick solution to this problem is to remove libopencv first, and then install libopencv 3.2.0 as shown below:

$ sudo apt purge --remove libopencv
$ sudo apt install libopencv-dev=3.2.0+dfsg-4ubuntu0.1

A consequence to this workaround is that the OpenCV 3.2.0 installed this way is CPU only. But for now ROS Melodic is working fine!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.