ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to tell Catkin_make to use opencv with gpu?

asked 2017-10-12 01:58:59 -0600

k_totoro gravatar image

updated 2017-10-13 23:06:17 -0600

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...

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-10-16 17:11:53 -0600

k_totoro gravatar image

updated 2017-10-17 18:43:29 -0600

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...

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 ...
(more)
edit flag offensive delete link more

Comments

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

TTDM gravatar image TTDM  ( 2017-10-17 03:54:11 -0600 )edit

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?

k_totoro gravatar image k_totoro  ( 2017-10-17 14:04:09 -0600 )edit
0

answered 2017-10-12 06:37:05 -0600

TTDM gravatar image

updated 2017-10-13 04:25:27 -0600

To compile a workspace with a specific version of OpenCV ( for exemple a version with Cuda ) see : https://answers.ros.org/question/2723...

You can look either at the accepted answer there or at my answer.

I don't believe you have any interest in recompiling all the packages included in the kinetic distribution (like CV_bridge) using a cuda enabled version of openCV. For your own packages, you should be working inside a workspace and in that case thelink is exactly what you need

Ps : a fast thought, what happen if you erase the build and devel directory of your workspace and compile using your current cmakefile ( in which the exact OpenCV path is specified ) ?

Edit: For the set(catkin_LIBRAIRIES first_lib_you_want; second_lib_you_want; ...), what you want to do is run your cmakelist one time printing the catkin_LIBRAIRIES and then you want to keep everything that's not an OpenCV lib and those are the libs you want to keep in your set.

edit flag offensive delete link more

Comments

Thank you for your comment. Deleting devel and build folder works to tell catkin the correct opencv dir. But I still have same problem may be because catkin_DIR has opencv path for ROS. The detail is in my updated question.

k_totoro gravatar image k_totoro  ( 2017-10-12 15:52:13 -0600 )edit

If you need it quickly, an awfull solution is to do a set(catkin_LIBRAIRIES first_lib_youwant; secondlibyouwant; ...) which is what i have done on all on the workspace on this PC, On an other PC, i have smth a lot cleaner but I don't really have time to check it for at least a week :( details in ans

TTDM gravatar image TTDM  ( 2017-10-13 04:17:26 -0600 )edit

Hi. I checked set(catkin_LIBRARIES ...) method works. I found including any opencv-ros lib in /opt/ros/kinetic/lib/ cause linking error. So I manually excluded whole libs named opencv from catkin_library.( more than 40! ) Do you know good way to do this automatically?

k_totoro gravatar image k_totoro  ( 2017-10-13 22:58:22 -0600 )edit

Hi. I found I just have to remove /opt/ros/kinetic/lib/libopencv_core3.so.3.2.0; from catkin_libraries. And now it seems my program can locate cuda function!

I put on the sample project here. https://github.com/YoshiRi/ros_opencv...

Thank you for your help!

k_totoro gravatar image k_totoro  ( 2017-10-13 23:35:38 -0600 )edit

well that's still a hack but at least it's a lot simpler to do it than to remove all libs manually ( as i was doing too ) . You welcome, and maybe smbd will come with a clean fix ;)

TTDM gravatar image TTDM  ( 2017-10-14 05:37:45 -0600 )edit

I checked the Cmakelist on my other PC (where i'm also using kinetic and cuda OpenCV and where it works without the hack) There isnt much difference with the CmakeList on this laptop where it doesn't work.. The only differences i saw was in the order on inclusion so I made a few test but no results.

TTDM gravatar image TTDM  ( 2017-10-14 05:46:34 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2017-10-12 01:58:59 -0600

Seen: 2,696 times

Last updated: Oct 17 '17