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

Revision history [back]

click to hide/show revision 1
initial version

In the while loop you have to wait for the images to arrive. By default your ptrs will be initialized to NULL, so accessing them before the call backs are called will fail; and you are guaranteed to do so at least in your first loop iteration of your while loop. Try something like:

 int count = 0;
  while (ros::ok())
  {
    if ( cv_ptr1 && cv_ptr2 )
    {
        //Here is usually your stitching-routine. 
       // Error won't occur here:
       image1 = cv_ptr1->image;     //Load the cv_bridge image into an OpenCV Matrix

       //Convert cv::Mat stitched to ROS image


       image_pub.publish(stitching_output);

       // after you have processed the image your might want to release them
       // so your node does not process the same images multiple times
       // reset the ptrs and wait for the callbacks to fill them again
       cv_ptr1.reset();
       cv_ptr2.reset();
    }
    else
    {
       // nothing can be done here; we have to spin and wait for images to arrive
    }


    ros::spinOnce();

    loop_rate.sleep();
    ++count;
  }