2

I am following image subscribe tutorial on official ROS page. when I run my_subscriber no window popup appears. I type -

rosrun image_transport_tutorial my_subscriber

output is -

init done
opengl support available

And then nothing happens. (even the output "init done" is unexplained because there is not output line in my_subscriber.cpp)

I am following this tutorial - ROS tutorial

I have roscore and rosrun image_transport_tutorial my_publisher pathtofile already running in dofferent terminals. I checked that publisher is publishing by running command

rostopic list -v

my_subscriber file has the following contents -

#include <ros/ros.h>
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <stdio.h>
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
  try
  {
    cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
  }
  catch (cv_bridge::Exception& e)
  {
    ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
  }
}

int main(int argc, char **argv)
{
  std::cout<<"kapil";
  ros::init(argc, argv, "image_listener");
  ros::NodeHandle nh;
  cv::namedWindow("view");
  cv::startWindowThread();
  image_transport::ImageTransport it(nh);
  image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback);
  ros::spin();
  cv::destroyWindow("view");
}

Solved : I added waitKey function in the try block as suggested in one of the answers.

cv::waitKey(30);
user12340
  • 663
  • 5
  • 6
  • Did you check if the topic camera/image is publishing something? Run this: $ rostopic list -v – Ha Dang Mar 10 '15 at 11:39
  • yes... i checked.. it is publishing. here is the output - Published topics: .. * /camera/image [sensor_msgs/Image] 1 publisher Subscribed topics: * /rosout [rosgraph_msgs/Log] 1 subscriber * /camera/image [sensor_msgs/Image] 1 subscriber – user12340 Mar 10 '15 at 11:40
  • if you have the package image_view install, try the following: $rosrun image_view image_view image:=/camera/image . Tell me what you got. – Ha Dang Mar 10 '15 at 11:44
  • I have it installed. it is not working. this is the output - [ INFO] [1425987943.187518428]: Using transport "raw" init done opengl support available (image_view:12714): GLib-GObject-WARNING **: invalid uninstantiatable type '(null)' in cast to 'GtkWidget' (image_view:12714): GLib-GObject-WARNING **: instance of invalid non-instantiatable type '(null)' (image_view:12714): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed – user12340 Mar 10 '15 at 11:48
  • try this: $rostopic echo /camera/image . Tell me what you get. – Ha Dang Mar 10 '15 at 11:51
  • I tried rostopic echo /camera/image. I am getting lots of numbers coming very fast... filling my terminal... i guess these are the camera pixel output. – user12340 Mar 10 '15 at 11:54
  • It looks like some libraries are missing. Try this: sudo apt-get install ros-[your ros distro here]-theora-image-transport – Ha Dang Mar 10 '15 at 12:12
  • tried it... no luck... :( .. it was already upgraded... I cant resolve the problem... i guess there is a problem in the subscriber.. i tried $rosrun rqt_graph rqt_graph . it was showing correct publisher, topic and subscriber.. as expected. – user12340 Mar 10 '15 at 12:22
  • I just tried the tutorial on my machine with ROS indigo installed. Everything works fine. – Ha Dang Mar 10 '15 at 12:24
  • Somebody else have the same problem [here](https://github.com/ros-perception/image_pipeline/issues/83). What's the configuration of your machine? Which ubuntu? Which ros distro? – Ha Dang Mar 10 '15 at 12:28
  • I am using ros-indigo, ubuntu 14.04. my machine is intel i5, 4gb ram.... – user12340 Mar 10 '15 at 12:32

1 Answers1

2

According to the comment to this answer, using cv::startWindowThread() does not always work. Maybe this is the issue in your case.

Try to add cv::waitKey(10) after cv::imshow instead. This will wait for some key press for 10 milliseconds, giving the window time to show the image. (This always seemed to me like a dirty hack, but it is the common way to show images in OpenCV...)

luator
  • 4,769
  • 3
  • 30
  • 51