0

SURF を使用するコードを C++ の「純粋な」OpenCV から ROS cpp コードに移行しようとしていました。問題は、surf Detector の行をインクルードすると、実行可能ファイルをリンクした後にコンパイラが以前に見たことのないエラーを表示することです。これは私のコードです:

#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