0
$\begingroup$

Rosanswers logo

Hi.

I have same trouble with this Having trouble using CUDA enabled OpenCV with kinetic.

My trouble is catkin_make is looking into only non-cuda function for ros-kinetic even I use NO_MODULE to tell exact opencv path.

Test CMakeLists.txt

So I made a test with CMakeLists.txt with following statement.

# find_package(Boost REQUIRED COMPONENTS system)
find_package(OpenCV REQUIRED
NO_MODULE # should be optional, tells CMake to use config mode
PATHS /usr/local # look here
NO_DEFAULT_PATH) # and don't look anywhere else

MESSAGE(WARNING "prefix ${CMAKE_PREFIX_PATH}")    
MESSAGE(WARNING "version ${OpenCV_VERSION}")
MESSAGE(WARNING "install path ${OpenCV_INSTALL_PATH}") 
MESSAGE(WARNING "config path ${OpenCV_CONFIG_PATH}") # look at the output of this message
MESSAGE(WARNING "include dirs ${OpenCV_INCLUDE_DIRS}")
MESSAGE(WARNING "libs ${OpenCV_LIBS}")

Test result

As a result, I can see catkin_make can correctly locate my opencv with cuda.

CMake Warning at CMakeLists.txt:10 (MESSAGE):
  version 3.1.0
    
CMake Warning at CMakeLists.txt:11 (MESSAGE):
  install path /usr/local
    
CMake Warning at CMakeLists.txt:12 (MESSAGE):
  config path /usr/local/share/OpenCV

CMake Warning at CMakeLists.txt:13 (MESSAGE):
  include dirs /usr/local/include/opencv;/usr/local/include

CMake Warning at CMakeLists.txt:14 (MESSAGE):
  libs
  opencv_xphoto;opencv_xobjdetect;opencv_ximgproc;opencv_xfeatures2d;opencv_tracking;opencv_text;opencv_surface_matching;opencv_structured_light;opencv_stereo;opencv_sfm;opencv_saliency;opencv_rgbd;opencv_reg;opencv_plot;opencv_optflow;opencv_line_descriptor;opencv_hdf;opencv_fuzzy;opencv_face;opencv_dpm;opencv_dnn;opencv_datasets;opencv_cvv;opencv_ccalib;opencv_bioinspired;opencv_bgsegm;opencv_aruco;opencv_videostab;opencv_videoio;opencv_video;opencv_superres;opencv_stitching;opencv_shape;opencv_photo;opencv_objdetect;opencv_ml;opencv_imgproc;opencv_imgcodecs;opencv_highgui;opencv_flann;opencv_features2d;opencv_cudev;opencv_cudawarping;opencv_cudastereo;opencv_cudaoptflow;opencv_cudaobjdetect;opencv_cudalegacy;opencv_cudaimgproc;opencv_cudafilters;opencv_cudafeatures2d;opencv_cudacodec;opencv_cudabgsegm;opencv_cudaarithm;opencv_core;opencv_calib3d

Problem : Catkin_LIB including

But I find my package still do not using opencv with cuda .

Now I found my $(catkin_LIBRARIES) including ros-kinetic-opencv3 lib.( This is necessary for the cv_bridge ) This is my ${catkin_INCLUDE_DIRS}. /opt/ros/kinetic/include;/opt/ros/kinetic/share/xmlrpcpp/cmake/../../../include/xmlrpcpp;/opt/ros/kinetic/include/opencv-3.2.0-dev;/opt/ros/kinetic/include/opencv-3.2.0-dev/opencv;/usr/include

Let me show some part of my CmakeLists.

include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
include_directories( include ${catkin_INCLUDE_DIRS} )  
...
target_link_libraries(my_function ${OpenCV_LIBS} ${catkin_LIBRARIES}) # this do not wrok
target_link_libraries(my_gpu_function ${OpenCV_LIBS} ) # this work

"my_function" linked with ${catkin_LIBRARIES} can not use gpu, on the other hand "my_gpu_function" linked only with ${OpenCV_LIBS} does. So I assume catkin_LIB have something to do with this problem.

Updated in 2017 Oct 13: test project

I found excluding every library named opencv from catkin_libraries do works.

I put on my sample project on here. https://github.com/YoshiRi/ros_opencv_conflict

This mean adding any of opencv3.2 in ros package cause the linker to lose cuda opencv function. Fortunately cv_bridge and image_transprot is safe to include, so I can build ros project but I feel very unease about this. Any one has any knowledge about this phenomena?

Question

How can I use both opencv cuda and cv_bridge and any other ros opencv related package in the same time in more better way?

Thank you.


Originally posted by k_totoro on ROS Answers with karma: 26 on 2017-10-12

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi previous me. I am still not sure how it works, but somehow I could make it work.

1. delete build and devel folder and recompile

Even after changing cmakelist, catkin_make still use previous package (I don't know why). Delete these folders can refresh some information and solve this problem.

2. Exclude /opt/ros/kinetic/lib/libopencv_core3.so.3.2.0; from catkin_LIBRARIES

After you told your opencv location to catkin_make, there is still ros-opencv reference information in that file. So, just delete that files using following command.

string(REPLACE "/opt/ros/kinetic/lib/libopencv_core3.so.3.2.0;" "" Modified_CLIBS "${catkin_LIBRARIES}")

Then, use this newly modified Modified_CLIBS instead of catkin_LIBRARIES.

For more detail, please look at my sample CMakeList.txt in test project. https://github.com/YoshiRi/ros_opencv_conflict

Ex. sometimes you need to exclude whole ros-opencv packages

I found in my another project, the method <2> do not work. So, I tried next ugly code, and it worked.

string(REPLACE "/opt/ros/kinetic/lib/libopencv_calib3d3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_core3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_features2d3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_flann3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_highgui3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_imgcodecs3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_imgproc3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_ml3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_objdetect3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_photo3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_shape3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_stitching3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_superres3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_video3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_videoio3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_videostab3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_viz3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_aruco3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_bgsegm3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_bioinspired3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_ccalib3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_cvv3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_datasets3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_dpm3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_face3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_fuzzy3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_hdf3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_line_descriptor3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_optflow3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_phase_unwrapping3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_plot3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_reg3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_rgbd3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_saliency3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_stereo3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_structured_light3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_surface_matching3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_text3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_xfeatures2d3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_ximgproc3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_xobjdetect3.so.3.2.0;/opt/ros/kinetic/lib/libopencv_xphoto3.so.3.2.0;" "" catkin_LIBRARIES "${catkin_LIBRARIES}")

Currently I just get this list from MESSAGE("${catkin_LIBRARIES}") but I should look for the better way to do this automatically. You can check which Opencv version your generated code depends on via:

cv::getBuildInformation()

And I noticed this result sometimes differ from following command:

std::cerr << "OpenCV version : " << CV_VERSION << std::endl;

Originally posted by k_totoro with karma: 26 on 2017-10-16

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by TTDM on 2017-10-17:
hi, seems nice and nearly generic to me but why not string(REPLACE "/opt/ros/kinetic/lib/libopencv_core3.so.3.2.0;" "" catkin_LIBRARIES "${catkin_LIBRARIES}") ? ( if it works ) ( and your CmakeList in your test project has not been edited ;) way better solution than mine anyway =D

Comment by k_totoro on 2017-10-17:
Hi. Your code should be work but I just want to separately use my gpu-opencv and ros-opencv. Did my test project worked in your environment?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.