2017-04-23 353 views
0

我正在使用ROS Kinetic並試圖編寫一個程序,該程序可以讀取兩個視頻並將它們發佈到兩個不同的主題上。但我認爲我在鏈接OpenCV庫時犯了一些錯誤。我收到以下錯誤。構建錯誤:未定義引用`cv_bridge :: CvImage :: toImageMsg()const'

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="[email protected]">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

它看起來不像你在cmake文件中鏈接cv_bridge。也許你想要這個:

find_package(catkin REQUIRED COMPONENTS 
    cv_bridge 
    roscpp 
    image_transport 
    OpenCV 
) 
+0

非常感謝約瑟夫! :) – Susan94

相關問題