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

Undefined reference to cv::Feature2D::compute

asked 2013-12-12 16:04:57 -0500

Marcus Lopes gravatar image

updated 2014-01-28 17:18:49 -0500

ngrennan gravatar image

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.

edit retag flag offensive close merge delete

Comments

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.

Marcus Lopes gravatar image Marcus Lopes  ( 2013-12-16 16:46:40 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-12-12 20:12:23 -0500

fergs gravatar image

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.

edit flag offensive delete link more

Comments

1

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.

Marcus Lopes gravatar image Marcus Lopes  ( 2013-12-12 23:10:24 -0500 )edit

I suggest you try out what's said here:

find_package(OpenCV REQUIRED)
target_link_libraries(foo ${catkin_LIBRARIES}
                          ${OpenCV_LIBRARIES})
tarunuday gravatar image tarunuday  ( 2018-07-07 17:36:49 -0500 )edit

Question Tools

Stats

Asked: 2013-12-12 16:04:57 -0500

Seen: 4,180 times

Last updated: Dec 13 '13