Setting CMakeLists.txt for OpenCV GPU and CUDA

Are you trying to compile this on the TX2? If so, the gpu:: libraries will not work if you’re using Opencv4Tegra right now. There was a compilation mistake which makes the gpu:: libraries unusable. The next update should have this fixed.

If you’ve build opencv from source, then a CMakeLists.txt file with contents similar to this should work!

cmake_minimum_required(VERSION X)
project(project_name)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(project_name source_file.cpp)
target_link_libraries(project_name ${OpenCV_LIBS})

You can find some OpenCV w/ CUDA and OpenCV w/o CUDA code on my GitHub page (ex: https://github.com/ShreyasSkandan/nvidia-tx1-tx2/tree/master/opencv_stuff/optical-flow)

Hope that answers your questions.