8489faustn
8489faustn

Reputation: 31

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

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.

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

When running rqt_graph with both the openni node and the tutorial file it looks like the this.

https://i.sstatic.net/GxYmt.jpg

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

Upvotes: 1

Views: 830

Answers (1)

8489faustn
8489faustn

Reputation: 31

I have fixed the issue by using rostpic hz [topic] and checking which ones are receiving camera data. From there, I changed the subscriber to image_sub_ = it_.subscribe("camera/rgb/image_color", 1, &ImageConverter::imageCb, this); and it worked

Upvotes: 2

Related Questions