[Solved] Ubuntu 18.04 Install opencv3.2.0 and opencv_contrib Error

After configuring the ROS melody environment for Jetson nano B01 and planning to install the turtle BOT, you need to install opencv3.2.0 and add GPU acceleration support to the compilation of OpenCV. There is a problem when installing opencv from the source code:

CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudaarithm/.cudaarithm

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudaarithm

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudabgsegm/.cudabgsegm

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudabgsegm

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudacodec/.cudacodec

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudacodec

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudafeatures2d/.cudafeatures2d

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudafeatures2d

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)

The reason is that the version of opencv_conteib is inconsistent with that of opencv. When cloning opencv, add -b 3.2.0. Similarly, when cloning opencv_contrib, clone version 3.2.0 and add -b 3.2.0, then no error will be reported.

Read More: