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

Linking opencv with ROS using cmake issue

asked 2016-05-18 07:37:17 -0600

polar gravatar image

updated 2016-05-18 07:38:18 -0600

Am getting this compilation error

../devel/lib/libXY.so: undefined reference to `cv::calcOpticalFlowPyrLK

In my CMake

find_package(OpenCV REQUIRED core imgproc highgui videoio  PATHS /home/polar/soft/lib/opencv/opencv-3.1.0/cmake)

... then

target_link_libraries(${file2link}
    ${catkin_LIBRARIES}
    ${MY_LIB}
    ${MY_LIB}
    ${gsl_LIBRARIES}
    # ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
    ${Boost_LIBRARIES}
    ${OpenCV_LIB} 
    ${OpenCV_LIBRARIES}
    ${OpenCV_LIBS} 
   )

For info, I installled opencv 3.1.0 myself. In XY.h I just call opencv like

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/features2d.hpp>
#include "opencv2/xfeatures2d.hpp"

Any idea on the source of the problem?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-10-12 17:00:56 -0600

A_KN gravatar image

updated 2017-08-22 11:29:10 -0600

jayess gravatar image

Make sure you have added all run and build dependencies in your package.xml If you used catkin_create_package YOUR_PACKAGE_NAME dependecy1 dependency2 as given in http://wiki.ros.org/ROS/Tutorials/cat... , then it is automatically added in your package.xml

Otherwise add these and any other dependencies you may need:

 <build_depend>cv_bridge</build_depend>
 <build_depend>image_transport</build_depend>
 <build_depend>roscpp</build_depend>
 <build_depend>sensor_msgs</build_depend>
 <build_depend>std_msgs</build_depend>

 <run_depend>cv_bridge</run_depend>
 <run_depend>image_transport</run_depend>
 <run_depend>roscpp</run_depend>
 <run_depend>sensor_msgs</run_depend>
 <run_depend>std_msgs</run_depend>
 <run_depend>OpenCV</run_depend>
edit flag offensive delete link more

Comments

@A_KN: I edited your answer for you but in the future please make sure to use the Preformatted Text (101010) button to make code snippets easier to read.

jayess gravatar image jayess  ( 2017-08-22 11:30:47 -0600 )edit
0

answered 2016-05-18 10:18:10 -0600

ROSkinect gravatar image

Try this:

find_package(catkin REQUIRED COMPONENTS     
     ${catkin_BUILD_PACKAGES} ) 
find_package(OpenCV REQUIRED)

target_link_libraries(${file2link}
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)
edit flag offensive delete link more

Comments

Still undefined reference to `cv::

polar gravatar image polar  ( 2016-05-18 21:23:54 -0600 )edit

Are you sure Opencv is installed?

And for find_package you shouldn't manually hardcode your paths or copy files around, I recommend you to remove this /home/polar/soft/lib/opencv/opencv-3.1.0/cmake It will probably work but it is not the way you should do it

Did you solve the problem?

ROSkinect gravatar image ROSkinect  ( 2016-05-19 04:36:53 -0600 )edit

OpenCV is well installed on my machine. I installed both 3.1.0 and 2.4.13. I can use them outside ros but not inside. Tried this but did not help a lot http://answers.ros.org/question/21404... Should I touch the package.xml?

polar gravatar image polar  ( 2016-06-02 06:45:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-18 07:37:17 -0600

Seen: 1,438 times

Last updated: Aug 22 '17