0

我试图将使用 SURF 的代码从 c++ 中的“纯”OpenCV 迁移到 ROS cpp 代码。问题是当我包含 surf Detector 的行时,编译器在 Linkin 可执行文件后向我显示我以前从未见过的错误。这是我的代码:

#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 <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/nonfree/nonfree.hpp"

using namespace cv;
using namespace std;
static const std::string OPENCV_WINDOW = "Image window";
class ImageConverter
{
  ros::NodeHandle nh_;
  image_transport::ImageTransport it_;
  image_transport::Subscriber image_sub_;
  image_transport::Publisher image_pub_;

public:
  ImageConverter()
    : it_(nh_)
  {
    // Subscribe to input video feed and publish output video feed
    image_sub_ = it_.subscribe("/ardrone/front/image_raw", 1, 
      &ImageConverter::imageCb, this);
    image_pub_ = it_.advertise("/image_converter/output_video", 1);

    namedWindow(OPENCV_WINDOW);
  }

  ~ImageConverter()
  {
    destroyWindow(OPENCV_WINDOW);
  }

  void imageCb(const sensor_msgs::ImageConstPtr& msg)
  {
    cv_bridge::CvImagePtr cv_ptr;
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return;
    }

    // Draw an example circle on the video stream

    Mat img_hsv;
    //cv::Mat img_gauss;
    //cv::Mat img_thr;
    //cv::GaussianBlur(cv_ptr->image, img_gauss, cv::Size(9,9), 1.5, 1.5);
    cvtColor(cv_ptr->image,img_hsv,CV_BGR2GRAY);
    //cv::inRange(img_hsv, cv::Scalar(60, 30, 20), cv::Scalar(140, 170, 128), img_hsv);
    // Update GUI Window
    //cv::imshow(OPENCV_WINDOW, cv_ptr->image);
    //cv::imshow(OPENCV_WINDOW, img_hsv);
    cv::imshow(OPENCV_WINDOW, img_hsv);
    int minHessian = 400;
    SurfFeatureDetector detector( minHessian );
        waitKey(3);

    // Output modified video stream
    image_pub_.publish(cv_ptr->toImageMsg());
  }
};

int main(int argc, char** argv)
{
  ros::init(argc, argv, "image_converter");
  ImageConverter ic;
  ros::spin();
  return 0;
}

打破一切的线是这样的:

SurfFeatureDetector detector( minHessian );

编译器向我显示的错误是:

Linking CXX executable /home/edrone/catkin_ws/devel/lib/stream/stream_node
CMakeFiles/stream_node.dir/src/stream_node.cpp.o: In function     `ImageConverter::imageCb(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
stream_node.cpp:  (.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x134): undefined reference to `cv::SURF::SURF(double, int, int, bool, bool)'
CMakeFiles/stream_node.dir/src/stream_node.cpp.o: In function `cv::SURF::~SURF()':
stream_node.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0xe): undefined reference to `vtable for cv::SURF'
stream_node.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x26): undefined reference to `vtable for cv::SURF'
stream_node.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x2e): undefined reference to `vtable for cv::SURF'
stream_node.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x3b): undefined reference to `VTT for cv::SURF'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/edrone/catkin_ws/devel/lib/stream/stream_node] Error 1
make[1]: *** [stream/CMakeFiles/stream_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

谢谢你的建议!

4

0 回答 0