构建错误:对`cv_bridge :: CvImage :: toImageMsg()const'的未定义引用

时间:2017-04-23 23:08:36

标签: c++ opencv ros

我正在使用ROS Kinetic并尝试编写一个程序,该程序可以读取两个视频并将它们发布在两个不同的主题上。但我认为我在链接OpenCV库方面犯了一些错误。我收到以下错误。

CMakeFiles/src.dir/src/src.cpp.o: In function `main':
src.cpp:(.text+0x3fd): undefined reference to `cv_bridge::CvImage::toImageMsg() const'
src.cpp:(.text+0x56d): undefined reference to `cv_bridge::CvImage::toImageMsg() const'
collect2: error: ld returned 1 exit status
MultiCamImages/CMakeFiles/src.dir/build.make:165: recipe for target 'MultiCamImages/src' failed
make[2]: *** [MultiCamImages/src] Error 1
CMakeFiles/Makefile2:1089: recipe for target 'MultiCamImages/CMakeFiles/src.dir/all' failed
make[1]: *** [MultiCamImages/CMakeFiles/src.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

这是我的源文件:

#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>

#include <opencv2/opencv.hpp>

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char** argv){
    ros::init(argc, argv, "PublishMultiCamImages");

    ros::NodeHandle nh;

    image_transport::ImageTransport it(nh);
    image_transport::Publisher pub1 = it.advertise("/camera/image_raw1", 1);
    image_transport::Publisher pub2 = it.advertise("/camera/image_raw2", 1);

    cv::Mat im;
    cv::String Path1("/home/akanksha/COSLAM_Dataset/EA-01/grayscale/*.jpg");
    cv::String Path2("/home/akanksha/COSLAM_Dataset/EA-02/grayscale/*.jpg");

    //time = ros::Time::now();

    vector<cv::String> fn1;
    vector<cv::String> fn2;
    cv::glob(Path1,fn1, true); // recurse
    cv::glob(Path2,fn2, true);

    ros::Rate r(50);

    int l1 = fn1.size();
    int l2 = fn2.size();

    int count1 = 0, count2 = 0;
    bool flag;
    while(ros::ok()){
        flag = true;
        if(count1 < l1){
            cv::Mat image1 = cv::imread(fn1[count1]);
            sensor_msgs::ImagePtr msg1 = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image1).toImageMsg();
            pub1.publish(msg1);
            count1++;
            flag = false;
        }
        if(count2 < l2){
            cv::Mat image2 = cv::imread(fn2[count2]);
            sensor_msgs::ImagePtr msg2 = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image2).toImageMsg();
            pub2.publish(msg2);
            count2++;
            flag = false;
        }

        if(flag)
            break;

        r.sleep();
    }

    ros::shutdown();

    return 0;


}

这是我的CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(MultiCamImages)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  image_transport
  OpenCV
)
# find_package(OpenCV REQUIRED)

set(OpenCV_LIBS opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_features2d opencv_ml opencv_highgui opencv_objdetect)

add_executable(src src/src.cpp)
target_link_libraries(src ${catkin_LIBRARIES} ${OpenCV_LIBS})

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES MultiCamImages
#  CATKIN_DEPENDS roscpp
#  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

这是我的pakage.xml

<?xml version="1.0"?>
<package>
  <name>MultiCamImages</name>
  <version>0.0.0</version>
  <description>The MultiCamImages package</description>

  <maintainer email="akanksha@todo.todo">akanksha</maintainer>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <run_depend>roscpp</run_depend>
  <build_depend>sensor_msgs</build_depend>
  <run_depend>sensor_msgs</run_depend>
  <build_depend>cv_bridge</build_depend>
  <run_depend>cv_bridge</run_depend>

</package>

如果你能指出这个问题会有很大的帮助。谢谢!

1 个答案:

答案 0 :(得分:2)

看起来你没有在cmake文件中链接cv_bridge。也许你想要这个:

shift_val