在ROS软件包中使用自定义OpenCV安装

时间:2019-03-15 00:31:47

标签: cmake opencv3.0 ros catkin

我正在尝试构建一个ROS软件包,其中使用了自定义OpenCV 3.4安装程序,其中启用了CUDA。在/ usr / local中的OpenCV安装工作正常,我可以使用

从GPU文件夹构建和运行示例,而没有问题
g++ -o houghlines houghlines.cpp `pkg-config opencv --cflags --libs`

但是,我只是无法让catkin使用我的OpenCV安装,而不是使用ROS附带的安装。这是我的CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(motion_segmentation_cuda)

set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.1/bin/nvcc)
find_package(catkin_simple REQUIRED)

set(OpenCV_INCLUDE_DIRS
  /usr/local/include
  /usr/local/include/opencv2
)
set(OpenCV_LIB_DIR
  /usr/local/lib
)
set(OpenCV_LIBS
  opencv_core
  opencv_highgui
  opencv_imgcodecs
)
include_directories(${OpenCV_INCLUDE_DIRS})

find_package(CUDA REQUIRED)
catkin_simple()

#Here you can set any gcc/cmake compiler flags, if you so wish
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
link_directories(${OpenCV_LIB_DIR})

#Add all of your sources here
cuda_add_executable(
  cuda_test_cu
  src/main.cpp
  src/motion_segmenter.cpp
  src/kernel.cu
  src/segmenter.cpp
)

#Link the executable to the necessary libs
target_link_libraries(
   cuda_test_cu
   ${catkin_LIBRARIES}
   ${OpenCV_LIBS}
   ${CUDA_LIBRARIES}
)

# CMake Indexing
FILE(GLOB_RECURSE LibFiles "include/*")
add_custom_target(headers SOURCES ${LibFiles})

cs_install()

在各种论坛的建议下,我也尝试过

export CMAKE_PREFIX_PATH="/usr/lib/:$CMAKE_PREFIX_PATH"
export LD_LIBRARY_PATH="/usr/lib/:$LD_LIBRARY_PATH"

以及CMakeLists中的大量调整。我的包编译就好了!但最后,我不可避免地得到:

OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/include/opencv2/core/private.cuda.hpp, line 107

一旦我尝试实际使用任何启用GPU的OpenCV类。

非常感谢!

1 个答案:

答案 0 :(得分:0)

要回答您的问题,请问我,此CMakeLists.txt可以运行(出于某种原因):

cmake_minimum_required(VERSION 2.8.3)
project(motion_segmentation_cuda)

find_package(OpenCV 3.4 REQUIRED
  COMPONENTS
    opencv_core
    opencv_highgui
    opencv_imgproc
    opencv_imgcodecs
  PATHS /usr/local
  NO_DEFAULT_PATH
  CONFIG
)

set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.1/bin/nvcc)
find_package(catkin_simple REQUIRED)
find_package(CUDA REQUIRED)
catkin_simple()

#Here you can set any gcc/cmake compiler flags, if you so wish
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")

include_directories(include ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})

#Add all of your sources here
cuda_add_executable(
  cuda_test_cu
  src/main.cpp
  src/motion_segmenter.cpp
  src/kernel.cu
  src/segmenter.cpp
)

#Link the executable to the necessary libs
target_link_libraries(
   cuda_test_cu
   ${catkin_LIBRARIES}
   ${OpenCV_LIBS}
   ${CUDA_LIBRARIES}
)

# CMake Indexing
FILE(GLOB_RECURSE LibFiles "include/*")
add_custom_target(headers SOURCES ${LibFiles})

cs_install()

最后无需更改.bashrc ...