0
$\begingroup$

Rosanswers logo

Hi,

I am running ROS Hydro and OpenCV 2.4.7, using openFabMap and SURF. When I do catkin_make on my project, I get the following error:

undefined reference to `cv::Feature2D::compute(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat&) const'

I noticed that this happens when I write the following line of code:

cv::SurfDescriptorExtractor extractor;
extractor.compute( cv_ptr->image, keypoints, descriptors_img);

UPDATE Other cv classes, such as the cv::SurfFeatureDetector detector class work normally. It even instantiates the cv::SurfDescriptorExtractor extractor with no problem. If I comment the "extractor.compute" call, I get no error.

I am including the following on the header:

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/opencv.hpp>

UPDATE And my (complete this time) CMakeLists:

cmake_minimum_required(VERSION 2.8.3)
project(compvision)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  image_transport
  cv_bridge
  sensor_msgs
  message_generation
)
find_package(OpenCV 2.4.7 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

 add_message_files(
    FILES 
    Match.msg
 )

 generate_messages(
   DEPENDENCIES
   std_msgs
 )

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES compvision
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
)

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

add_executable(openFABMAPros src/fabmapTest.cpp)
target_link_libraries(openFABMAPros ${catkin_LIBRARIES})
target_link_libraries(openFABMAPros ${OpenCV_LIBRARIES})
add_dependencies(openFABMAPros ${catkin_EXPORTED_TARGETS})

add_executable(image_converter src/image_converter.cpp)
target_link_libraries(image_converter ${catkin_LIBRARIES})
target_link_libraries(image_converter ${OpenCV_LIBRARIES})
add_dependencies(image_converter ${catkin_EXPORTED_TARGETS})

Am I missing some dependencies? I don't recall this error happening when building with earlier versions of OpenCV.

Thanks for your time and support.


Originally posted by Marcus Lopes on ROS Answers with karma: 1 on 2013-12-12

Post score: 0


Original comments

Comment by Marcus Lopes on 2013-12-16:
Installing ROS on another machine and running the same code there worked just fine ... well, I still don't know what might have happened, but that solved the problem for me.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Presumably there is more in your CMakeLists, in particular you have a line like:

add_executable(foo foo.cpp)

What you are probably missing is:

target_link_libraries(foo ${catkin_LIBRARIES}
                          ${OpenCV_LIBRARIES})

to actually link against the OpenCV libraries.


Originally posted by fergs with karma: 13902 on 2013-12-12

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Marcus Lopes on 2013-12-13:
Thanks for the fast reply, fergs. So, I was fighting with the editor, but I managed to upload the whole CMakeLists file. It turns out I had the OpenCV_LIBS included there. I tried it with the syntax you used, but I got the same problem.

Comment by tarunuday on 2018-07-07:
I suggest you try out what's said here:

find_package(OpenCV REQUIRED)
target_link_libraries(foo ${catkin_LIBRARIES}
                          ${OpenCV_LIBRARIES})
$\endgroup$

Your Answer

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