OpenCV - compile OpenCV 4.1.1 on Drive Software 10.0

Note: OpenCV is not officially supported nor is it optimized on the Drive platform. These instructions are provided only to help with porting/prototyping and is not maintained by NVIDIA. It is recommended to utilize NVIDIA APIs moving forward.

Cross compiling OpenCV on host

Pre-Conditions:

  1. Drive Software 10.0 is installed on the host machine via SDKManager (both host and device).
  2. cmake is installed (min version 3.10)

The instructions to build OpenCV on Host machine for Drive AGX Linux (V4L) platform:

  1. Download attached file “FindCUDA.cmake” FindCUDA.cmake.zip (21.3 KB)
  2. cd <the_folder_where_FindCUDA.cmake_was_downloaded_to>
  3. execute the following commands:
    curl -L https://github.com/opencv/opencv/archive/4.1.1.zip -o opencv-4.1.1.zip
    curl -L https://github.com/opencv/opencv_contrib/archive/4.1.1.zip -o opencv_contrib-4.1.1.zip
    curl -L https://github.com/opencv/opencv_extra/archive/4.1.1.zip -o opencv_extra-4.1.1.zip
    unzip opencv-4.1.1.zip
    unzip opencv_extra-4.1.1.zip
    unzip opencv_contrib-4.1.1.zip
    cd opencv-4.1.1/
    echo "** Apply patch"
    sed -i 's/include <Eigen\/Core>/include <eigen3\/Eigen\/Core>/g' modules/core/include/opencv2/core/private.hpp
    cp ../FindCUDA.cmake cmake/
    cp /usr/local/driveworks/samples/cmake/FindCUDA/* cmake/FindCUDA/
    cp /usr/local/driveworks/samples/cmake/CMakeParseArguments.cmake cmake/
    cp /usr/local/driveworks/samples/cmake/FindPackageHandleStandardArgs.cmake cmake/
    cp /usr/local/driveworks/samples/cmake/FindPackageMessage.cmake cmake/
    echo "** Building..."
    mkdir release
    cd release/
    export CUDA_PATH=/usr/local/cuda-10.2
    cmake \
    -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules \
    -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 \
    -DCUDA_64_BIT_DEVICE_CODE=ON \
    -DCUDA_ARCH_BIN=7.2 \
    -DCUDA_ARCH_PTX="" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_TOOLCHAIN_FILE=/usr/local/driveworks/samples/cmake/Toolchain-V5L.cmake \
    -DCMAKE_INSTALL_PREFIX=./install \
    -DVIBRANTE_PDK:STRING=<path_to_drive-t186ref-linux_location>/drive-t186ref-linux \
    -DBUILD_PNG=ON \
    -DBUILD_TIFF=ON \
    -DBUILD_TBB=OFF \
    -DBUILD_WEBP=OFF \
    -DBUILD_JPEG=ON \
    -DBUILD_JASPER=ON \
    -DBUILD_ZLIB=ON \
    -DBUILD_EXAMPLES=ON \
    -DBUILD_FFMPEG=ON \
    -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_python2=OFF \
    -DBUILD_opencv_python3=OFF \
    -DBUILD_opencv_videoio=OFF \
    -DBUILD_opencv_cudaimgproc=OFF \
    -DBUILD_opencv_highgui=OFF \
    -DBUILD_opencv_freetype=OFF \
    -DENABLE_NEON=ON \
    -DWITH_PROTOBUF=OFF \
    -DWITH_PTHREADS_PF=OFF \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENMP=OFF \
    -DWITH_FFMPEG=ON \
    -DWITH_GSTREAMER=OFF \
    -DWITH_GSTREAMER_0_10=OFF \
    -DWITH_CUDA=ON \
    -DWITH_CUDNN=ON \
    -DCUDNN_INCLUDE_DIR=/usr/include/aarch64-linux-gnu \
    -DWITH_GTK=OFF \
    -DWITH_VTK=OFF \
    -DWITH_TBB=OFF \
    -DWITH_1394=OFF \
    -DWITH_OPENEXR=OFF \
    -DINSTALL_C_EXAMPLES=ON \
    -DINSTALL_TESTS=OFF \
    -DVIBRANTE=TRUE \
    VERBOSE=1 \
    -DOPENCV_CUDA_FORCE_BUILTIN_CMAKE_MODULE=TRUE \
    -DOPENCV_TEST_DATA_PATH=../opencv_extra-4.1.1/testdata \
    ../
    make -j8
    make install

native compiling OpenCV on AGX Drive
Pre-Conditions:

  1. Drive AGX hardware: Xavier or Pegasus.
  2. The latest Nvidia Drive Software is installed, SDK can be downloaded from : https://developer.nvidia.com/nvidia-drive-downloads

The instructions to build OpenCV on Drive AGX Linux (V4L) platform:

  1. Execute the command: sudo apt update
  2. Execute the command: sudo dpkg -i /var/cuda-repo-10-2-local-10.2.19/cuda-toolkit-10-2_10.2.19-1_arm64.deb
  3. Execute the command: sudo apt --fix-broken -y install
  4. Run the script “install_oprncv4.11_Jeston.sh” attached here.install_opencv4.1.1.zip (1.3 KB)

Hello,

I did the cross compiling steps without errors and it installed in the release/install directory. For some reason DVIBRANTE_PDK:STRING had no effect, so I had to copy the contents of release/install to targetfs manually. When I try to run the command “dpkg -l | grep libopencv” nothing shows. Also when I try to import cv2 in a python program I get the error “No module named cv2”.

Could you please support and advise regarding the problem presented above?
It is possible that I have not deployed OpenCV correctly to the target.

Thank you!

hello liviu.poenaru,

  1. the cross-compilation documentation above does not include opencv for python libs. to cross-compile OpenCV with Python you need first to install cross-compilation libs and define the following environment variables:
    PYTHON2_INCLUDE_PATH
    PYTHON2_LIBRARIES
    PYTHON2_NUMPY_INCLUDE_DIRS
    PYTHON3_INCLUDE_PATH
    PYTHON3_LIBRARIES
    PYTHON3_NUMPY_INCLUDE_DIRS

  2. to install opencv on a different location change the parameter:
    -DCMAKE_INSTALL_PREFIX=./install

  3. dpkg will not give you the opencv package as you haven’t installed it on the drive, to install it on the drive run “make install” on the Drive platform after copying the compiled opencv release folder and defining -DCMAKE_INSTALL_PREFIX=/usr/local when running cmake.

alternatively,
you can choose the second option for installing it on the AGX Drive: native compiling OpenCV on AGX Drive

Hi @shayNV,

If we would do the native compile on the AGX DRIVE, where should we install it?

Cheers,
Niels

Hi @shayNV

What would be the difference in the configuration for DRIVE™ OS 5.2.0 since the /usr/local/driveworks/samples/cmake/FindCUDA/ folder doesn’t exist.

I would like to know two things from the configuration above:

  • ENABLE_VFPV3 is not used? Why?

  • Why is WITH_TBB OFF?