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

streaming AR.Drone 2.0 images to OpenCV

asked 2014-09-26 13:31:55 -0500

voladoddi gravatar image

I'm following these tutorials to stream images to OpenCV format from the /ardrone/image_raw topic.

http://wiki.ros.org/cv_bridge/Tutoria...

However, even though I've been able to successfully compile the driver, when i run it, I don't see any images on screen. My code is this -

#include "ros/ros.h"
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "ardrone_autonomy/Navdata.h"

static const std::string OPENCV_WINDOW = "Image window";

class ImageConverter
{
  ros::NodeHandle nh_;
  image_transport::ImageTransport it_;      //ImageTransport object "it_" under the namespace 'image_transport'
  image_transport::Subscriber image_sub_;       //Subscriber object "image_sub_"
  image_transport::Publisher image_pub_;        // Publisher object "image_pub_"

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

          cv::namedWindow(OPENCV_WINDOW);
    }

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

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

    // Draw an example circle on the video stream
    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));

    // Update GUI Window
    cv::imshow(OPENCV_WINDOW, cv_ptr->image);
    cv::waitKey(3);

    // Output modified video stream
    image_pub_.publish(cv_ptr->toImageMsg());
  }
};

int main(int argc, char** argv)
{
  ros::init(argc, argv, "see_image");
  ImageConverter ic;
  ros::spin();
  return 0;
}

After executing this, rosrun [package_name] [driver_node] along with a recorded .bagfile, it is supposed to produce image stream with a circle on it.

I can see when I run rqt_graph both the bag file and the driver node. However, I don't see any image. What am I missing? I've lost about a week in looking at this.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-09-26 16:59:37 -0500

voladoddi gravatar image

For those who are stuck in the same position as me, you might want to check your bag file. Mine didn't have any images in them.

But I got stuck here for a while because /ardrone/image_raw was displayed when I called rostopic list. In this case you want to make sure that your images were considerable in message numbers.

1) Check your rosbag using rosbag info [bag_file] to see if the message is listed. 2) Try visualizing in rviz if the image is displayed while running the bag file. 3) rqt_graph for connection of topics.

Cheers.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-26 13:31:55 -0500

Seen: 1,010 times

Last updated: Sep 26 '14