ROS and OpenCV with CUDA on Jetson Nano : Incompatible versions

Viewed 1890

I want to use ROS with CUDA-enabled OpenCV on my Jetson Nano. At this point I don´t care about the versions.

The problem: Jetson Nano only supports CUDA 10 and Ubuntu 18.04. The ROS version for Ubuntu 18.04 is Melodic, which needs OpenCV 3.2, but OpenCV 3.2 only supports CUDA 8.

I have found a guide here on SO (CMake Error: Variables are set to NOTFOUND) to build it with CUDA 9, but it fails when trying it with CUDA 10 due to "error: identifier "__shfl_down" is undefined", and some other "__shfl_XXX" errors.

Anyone here succeeded in getting this to work? Or any idea on how to fix the "__shfl_down" error?

Can OpenCV 3.2 work with CUDA 10.2?

2 Answers
  1. Option 01:

    Nope, do not try to build with CUDA 10.2, this is my suggestion in which you are in safe side both ways. In your package CMakeLists.txt add your alternative OpenCV (comes with Nano) as follows while assumimg main.cpp is the your main file, if not change it:

       set(OpenCV_INCLUDE_DIRS
          <path_to>/include
          <path_to>/include/opencv2
        )
    
        set(OpenCV_LIB_DIR
          <path_to>/lib
        )
    
        set(OpenCV_LIBS
          opencv_core
          opencv_highgui
          opencv_imgcodecs
        )
    
        include_directories(${OpenCV_INCLUDE_DIRS})
        link_directories(${OpenCV_LIB_DIR})
        add_executable(${PROJECT_NAME} src/main.cpp)
        target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
    

    Under OpenCV_LIBS add OpenCV modules you use in your code

    Note: I am not a position to test this on my machine, so consider this as a tentative answer, if you have problems let me know, I will try to help

  2. Option 02:

    catkin_make -DOpenCV_DIR=/usr/local/share/OpenCV

    Note: OpenCV_DIR must point to a folder with opencv-conifg.cmake file. More information can be found here

I found a solution, even though I have not done extensive testing on it yet:

  1. Build OpenCV 4.2 (any version that supports CUDA 10.2 should work) from source, enabling CUDA. A good guide is available at https://www.pyimagesearch.com/2020/03/25/how-to-configure-your-nvidia-jetson-nano-for-computer-vision-and-deep-learning/ (skip parts with tensorflow etc)

  2. Install ROS Melodic. No need to build from source.

  3. After creating a workspace, clone the cv_bridge and image_transport modules into it. IMPORTANT: Switch to branch "Noetic"!

  4. In the CMakeLists.txt in cv_bridge, change the find_package(Boost REQUIRED python37) to find_package(BOOST REQUIRED python)

  5. In cv_bridge/src/module.hpp in the function do_numpy_import, change the return type from void* to void, and remove the return nullptr;

  6. Build the workspace with catkin. It should build normally.

I have tested a basic image publish, and viewing it in rqt_image_view. Works like a charm!

I know this is a bit of a hacky solution, so if anyone knows something better, please let me know!

Related