Ask Your Question

cv_bridge tutorial program (ROS node) not working. [closed]

asked 2014-01-29 13:00:46 -0600

lifelonglearner gravatar image

updated 2014-01-29 18:03:39 -0600

I created a node using catkin work space after creating package the process of build is successful with following code .... but the problem is when I am running it using rosrun cvtest image_converter.cpp the run is successful but i am not getting the output.
The image_converter.cpp which suppose to subscribe sensor_msgs topic and convert the image to opencv::mat process the image and then display it back in ROS. To publish the message on sensor_msgs topic as the frame captured from kinect I am using roslaunch openni_launch openni.launch.
However I can see the image using rosrun image_view image_view image:=/camera/rgb/image_color which also subscribes the same topic sensor_msgs.

Tried it with eclipse also but it is not working at all and unable to find the problem even in eclipse. its running there but no output.

I am including the roswtf result also. (pls see after the code)

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

namespace enc = sensor_msgs::image_encodings;

static const char WINDOW[] = "Image window";

class ImageConverter
   ros::NodeHandle nh_;
   image_transport::ImageTransport it_;
   image_transport::Subscriber image_sub_;
   image_transport::Publisher image_pub_;

     : it_(nh_)
     image_pub_ = it_.advertise("out", 1);
     image_sub_ = it_.subscribe("in", 1, &amp;ImageConverter::imageCb, this);



   void imageCb(const sensor_msgs::ImageConstPtr&amp; msg)
     cv_bridge::CvImagePtr cv_ptr;
       cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8);
     catch (cv_bridge::Exception&amp; e)
       ROS_ERROR("cv_bridge exception: %s", e.what());

     if (cv_ptr-&gt;image.rows &gt; 60 &amp;&amp; cv_ptr-&gt;image.cols &gt; 60)
       cv::circle(cv_ptr-&gt;image, cv::Point(50, 50), 10, CV_RGB(255,0,0));

     cv::imshow(WINDOW, cv_ptr-&gt;image);


 int main(int argc, char** argv)
   ros::init(argc, argv, "image_converter");
   ImageConverter ic;
   return 0;

Here is roswtf result

admin-pc@admin-pc:~/mywork$ roswtf
No package or stack in context
Static checks summary:

Found 2 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING You are missing core ROS Python modules: bloom -- rosrelease -- 
WARNING You are missing Debian packages for core ROS Python modules: bloom (python-bloom) -- rosrelease (python-rosrelease) -- 

Beginning tests of your ROS graph. These may take awhile...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules

Online checks summary:

Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING The following node subscriptions are unconnected:
 * /image_converter:
   * /in


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by lifelonglearner
close date 2014-01-30 12:07:48

1 Answer

Sort by » oldest newest most voted

answered 2014-01-29 22:31:08 -0600

Wolf gravatar image

You need to remap topic "in" of your converter to "/camera/rgb/image_color" (Output image of your camera). Try running it by:

rosrun cvtest image_converter.cpp in:=/camera/rgb/image_color
edit flag offensive delete link more


Thank you for your help, it worked finally.

lifelonglearner gravatar image lifelonglearner  ( 2014-01-29 23:03:00 -0600 )edit

Question Tools

1 follower


Asked: 2014-01-29 13:00:46 -0600

Seen: 608 times

Last updated: Jan 29 '14