ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Order of nodes in roslaunch for accessing camera images

asked 2015-03-08 01:02:10 -0600

rookie gravatar image

updated 2015-03-08 03:33:37 -0600

I am trying to run two nodes, one being the usb_cam node to start the camera and the second node to use the images for image processing. As there is no particular order in which the nodes are launched, the image processing node doesn't start displaying the highgui window as I'd written, which I think is probably because the usb_cam node hasn't started ?

It works fine when I run the node independently using rosrun, starting usb_cam node first and then the image processing thread.

How can I solve this problem?


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

            : it_(nh_)
         // Subscrive to input video feed and publish output video feed
          image_sub_ = it_.subscribe("/usb_cam/image_raw", 1,
          &ImageConverter::imageCb, this);
           image_pub_ = it_.advertise("/image_converter/output_video", 1);



          void imageCb(const sensor_msgs::ImageConstPtr& msg)

         cv::Mat img, img_resize;

              img = cv_bridge::toCvCopy(msg, "mono8")->image;
            catch (cv_bridge::Exception& e)
              ROS_ERROR("cv_bridge exception: %s", e.what());

            if (img.rows > 60 && img.cols > 60)
                   cv::circle(img, cv::Point(50, 50), 10, CV_RGB(255,0,0));

              cv::resize(img, img_resize, cv::Size2i(img.cols/2, img.rows/2));

              cv::imshow(OPENCV_WINDOW, img_resize);


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

Launch File:


      <node pkg="usb_cam" type="usb_cam_node" name="usbcam" required="true" clear_params="true" >
           <param name="video_device" value="/dev/video0" />

      <node pkg="opencv_ros" type="image" name="image" required="true" clear_params="true" output="screen"/>


It gives me an error

       Webcam: expected picture but didn't get it...

       No JPEG data  found in image

       Error while decoding frame.

but this happens just once(first time I run it after booting). After I kill the process and run it again, it doesn't show this error, but the highui window doesn't open either.

edit retag flag offensive close merge delete



These is no specific order in roslaunch - all nodes are started in parallel. Without seeing your code it is difficult to give any advice. Are both nodes running (rosnode list)? Does it output any error messages?

Dirk Thomas gravatar image Dirk Thomas  ( 2015-03-08 01:50:36 -0600 )edit

I have added my piece of code to the question. I hope that will help identify the problem. rosnode list shows three nodes acc to launch file: usbcam, image and rosout

rookie gravatar image rookie  ( 2015-03-08 03:34:18 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-13 08:14:07 -0600

updated 2016-04-13 08:50:07 -0600


You can add a .bash to the roslaunch in order to delay the launch. There is a previous answer with an example on how to do this.

The other option is to call the roslaunch from a .bash file, and simply add pauses in the .bash

Here is an example:

echo "Run simulation full system"

echo "Launching: maps.launch"

gnome-terminal -x sh -c "roslaunch foo maps.launch; exit"

echo "Waiting 30s left"

sleep 30

echo "Launching: planning.launch"

gnome-terminal -x sh -c "roslaunch foo planning.launch; exit"

echo "Waiting 1m left"

sleep 60

"Launching: movement.launch"

gnome-terminal -x sh -c "roslaunch foo movement.launch; exit" `


edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-03-08 01:02:10 -0600

Seen: 2,300 times

Last updated: Apr 13 '16