cv_bridge tutorial program (ROS node) not working. [closed]
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, &ImageConverter::imageCb, this);
cv::namedWindow(WINDOW);
}
~ImageConverter()
{
cv::destroyWindow(WINDOW);
}
void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
cv_bridge::CvImagePtr cv_ptr;
try
{
cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
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));
cv::imshow(WINDOW, cv_ptr->image);
cv::waitKey(3);
image_pub_.publish(cv_ptr->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>