关于解决libopencv_core.so.2.4, needed by /../libcv_bridge.so, may conflict with libopencv_core.so.3.1

当使用opencv3.1版本的时候,有时候会出现问题。原因是在安装ros-indigo-desktop-full 的时候有些package依赖于opencv2.4.8,例如cv_bridge or image_pipeline等package 。

#include 
#include 
#include 
#include 
#include 
#include 

using std::cout;
using std::endl;
using std::stringstream;
using std::string;

unsigned int fileNum = 1;
bool saveCloud(false);

void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
  cv::imshow("Show RgbImage", cv_bridge::toCvShare(msg,"rgb8")->image);
  char key;
  key=cvWaitKey(33);
  if(key==32)           //the Ascii of "Space key" is 32
  saveCloud = true;
  if(saveCloud)
  {
    stringstream stream;
    stringstream stream1;
    stream <<"Goal RgbImage" << fileNum<<".jpg";
    stream1 <<"/home/hansry/qt_catkin_ws2/src/linkage_point/" << fileNum <<".jpg";
    string filename = stream.str();
    string filename1 = stream1.str();
cv::imwrite(filename1,cv_bridge::toCvShare(msg)->image);//保存图片
    saveCloud = false;
    fileNum++;
    cout << filename << " had Saved."<< endl;
  }
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "Image_listener");
  ros::NodeHandle nh;
  cv::namedWindow("Show RgbImage");//用于创建一个窗口
  cv::startWindowThread();
  image_transport::ImageTransport it(nh);
  image_transport::Subscriber sub = it.subscribe("/camera/rgb/image_raw", 1, imageCallback);
  //image_transport::Subscriber sub = it.subscribe("/camera/ir/camera", 1,);
  ros::spin();
  cv::destroyWindow("Show RgbImage");
}

Cmakelist文件为:

cmake_minimum_required(VERSION 2.8.3)
project(Detect_mark)
find_package(catkin REQUIRED COMPONENTS
    sensor_msgs
    cv_bridge
    std_msgs
    image_transport
  roscpp
)
#find_package( OpenCV REQUIRED )
set(OpenCV_DIR /usr/local/opencv310/share/OpenCV)
find_package(OpenCV 3.1 REQUIRED )
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS} /usr/local/opencv310/include)
find_package( "/usr/local/opencv310/include/opencv2" )
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
include_directories(
  ${catkin_INCLUDE_DIRS}
   ${OpenCV_INCLUDE_DIRS}
)
add_executable(Detect_mark src/Detect_mark.cpp)
target_link_libraries(Detect_mark
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

该程序中订阅了Xtion里面的一个节点,然后通过回调函数将图像显示出来并且保存,但是在这里中,我们需要将ROS支持的图片格式转换成opencv3支持的图片格式,这就需要用到cv::bridge(我们安装ros的时候是依赖与opencv2的),直接编译会出现以下问题:

/usr/bin/ld: warning: libopencv_imgproc.so.2.4, needed by /opt/ros/indigo/lib/libcv_bridge.so, may conflict with libopencv_imgproc.so.3.0
/usr/bin/ld: warning: libopencv_core.so.2.4, needed by /opt/ros/indigo/lib/libcv_bridge.so, may conflict with libopencv_core.so.3.0

解决方法是:
分别下载cv_bridge or image_pipeline等package到你的src目录下面,然后在工作空间catkin_make一下(即重新编译)即可,下载链接分别为:https://github.com/ros-perception/ima...https://github.com/ros-perception/vis...
如下图所示:

这里写图片描述

除了cpp文件之外,还有下载的vision_opencv,即上述的俩个链接,即可解决上面的问题,得到结果如下:

这里写图片描述

正常使用!!!

你可能感兴趣的:(Robotic,Operation,System)