Using Custom OpenCV Build in Ros Package
Hi all!
I want to use OpenCV cuda libraries, so I built OpenCV 3.4 in /usr/local. I cannot for the life of me work out how to get catkin to use this install instead of the custom ROS install. I have looked at many other forum posts over the last two days, just trying to get this to work. Here's what I have tried:
Setting the paths in 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})
message(STATUS ${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()
Exporting the paths in .bashrc:
export CMAKE_PREFIX_PATH="/usr/lib/:$CMAKE_PREFIX_PATH"
export LD_LIBRARY_PATH="/usr/local/lib"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export CPATH="/usr/local/include"
I have also tried just going into /opt/ros/kinetic/ and just replacing the OpenCV folder with symlinks and editing the CMakeLists that reference them appropriately (though this caused even more problems).
I'm at the end of my tether and can't think of anything else to do. I know that there are other posts dealing with this, but chances are I've seen it if it's out there and it hasn't worked...
Many thanks for your help.
I wish I had a good answer for you. I was never able to get a locally compiled OpenCV to work the way you are doing it, but I almost had OpenCV working in a catkin package in my workspace.
I was able to create a catkin package of OpenCV 3.4.6 using a modification of the script on this page (http://wiki.ros.org/opencv3) and using a modification of the package.xml for lunar in opencv3-release (also mentioned on that page).
This compiled successfully in my melodic workspace, but stereo_image_proc only linked to its libraries sporadically. Ug. I was also compiling vision_opencv in my workspace because I have read that is required when trying to link with a local OpenCV. If you can get it to link consistently I would love to know how you do it.