简体   繁体   English

按照初学者 cv_bridge 教程,不起作用

[英]Following the beginner cv_bridge tutorials, doesn't work

I am trying to bridge Ros images to OpenCV so i started using cv_bridge and followed this tutorial.我正在尝试将 Ros 图像桥接到 OpenCV,所以我开始使用 cv_bridge 并遵循本教程。 http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

I think I was able to make the CMakeLists.txt file correct and using catkin_make does build the executable and the code runs, however nothing really happens besides the node showing up as a leaf topic when using rqt_graph .我想我能够使CMakeLists.txt文件正确,并且使用catkin_make确实构建了可执行文件并运行了代码,但是除了使用rqt_graph时节点显示为叶主题之外,没有任何实际发生。

However, i ran into some issues with the line of the tutorial where it says: Run a camera or play a bag file to generate the image stream.但是,我在教程中遇到了一些问题:运行相机或播放包文件以生成图像流。 Now you can run this node, remapping "in" to the actual image stream topic.现在您可以运行此节点,将“输入”重新映射到实际的图像流主题。

I am using a Kinect for the image source and have installed the openni drivers and can confirm that it is working correctly, as when i run rviz or rtabmap point cloud images is being shown.我正在使用 Kinect 作为图像源并安装了 openni 驱动程序,并且可以确认它是否正常工作,就像我运行 rviz 或 rtabmap 时显示的点云图像一样。

I'm guessing the issue is that i am not mapping the publishers and subscribers correctly, as when i am trying to use image_view to see if the camera data is working it returns blank.我猜问题是我没有正确映射发布者和订阅者,因为当我尝试使用 image_view 来查看相机数据是否正常工作时,它返回空白。 In the command line, i am typing in: rosrun image_view image_view image:=/camera/rgb/image_color However, I am receiving this error: GLib-GObject-CRITICAL **: 15:13:13.357: g_object_unref: assertion 'G_IS_OBJECT (object)' failed , which i'm assuming is an error with me renaming the topics.在命令行中,我输入: rosrun image_view image_view image:=/camera/rgb/image_color但是,我收到此错误: GLib-GObject-CRITICAL **: 15:13:13.357: g_object_unref: assertion 'G_IS_OBJECT (object)' failed ,我假设这是我重命名主题的错误。

When running rqt_graph with both the openni node and the tutorial file it looks like the this.当使用rqt_graph节点和教程文件运行rqt_graph ,它看起来像这样。

https://imgur.com/fLd69WG https://imgur.com/fLd69WG

#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>

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_)
  {
    // Subscrive to input video feed and publish output video feed
   //I'm guessing this is where my errors are
    image_sub_ = it_.subscribe("/camera/image_raw", 1,
    &ImageConverter::imageCb, this);
    image_pub_ = it_.advertise("/image_converter/output_video", 1);

    cv::namedWindow(OPENCV_WINDOW);
  }

  ~ImageConverter()
  {
    cv::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
    if (cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)
      cv::circle(cv_ptr->image, cv::Point(50, 50), 10, CV_RGB(255,0,0));

    // Update GUI Window
    cv::imshow(OPENCV_WINDOW, cv_ptr->image);
    cv::waitKey(3);

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

int main(int argc, char** argv)
{
   ros::init(argc, argv, "image_converter");
   ROS_INFO_STREAM("test to see if node is running");
  ImageConverter ic;
  ros::spin();
  return 0;
}

I have fixed the issue by using rostpic hz [topic] and checking which ones are receiving camera data.我通过使用rostpic hz [topic]并检查哪些正在接收相机数据来解决这个问题。 From there, I changed the subscriber to image_sub_ = it_.subscribe("camera/rgb/image_color", 1, &ImageConverter::imageCb, this);从那里,我将订阅者更改为image_sub_ = it_.subscribe("camera/rgb/image_color", 1, &ImageConverter::imageCb, this); and it worked它起作用了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM