Ask Your Question
0

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

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

lifelonglearner gravatar image

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

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_;

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

     cv::namedWindow(WINDOW);
   }

   ~ImageConverter()
   {
     cv::destroyWindow(WINDOW);
   }

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

     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);
     cv::waitKey(3);

     image_pub_.publish(cv_ptr-&gt;toImageMsg());
   }
 };

 int main(int argc, char** argv)
 {
   ros::init(argc, argv, "image_converter");
   ImageConverter ic;
   ros::spin();
   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

</opencv2></opencv2></sensor_msgs></cv_bridge></image_transport></ros>

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
1

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

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

Comments

Thank you for your help, it worked finally.

lifelonglearner gravatar imagelifelonglearner ( 2014-01-29 23:03:00 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 525 times

Last updated: Jan 29 '14