problem with cv_bridge [closed]

asked 2013-11-27 21:38:24 -0500

Hamid Didari gravatar image

updated 2013-12-21 07:36:24 -0500

tfoote gravatar image

Hi dear I tried to follow cv_bridge example for this I ran cv_camera to get image from webcam and ran the example of cv_bridge but the example couldn't subscribe any message. the example program:

#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("/camera/image_raw", 100,
      &ImageConverter::imageCb, this);
    image_pub_ = it_.advertise("/image_converter/output_video", 1);



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

    // 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);

    // Output modified video stream

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

could some one help me? I'm using ubuntu 12.10 and hydro

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2014-11-23 13:56:19.218749


When you run cv_camera, does the topic "/camera/image_raw" show up when you do a "$rostopic list"?

Angus gravatar image Angus  ( 2013-11-28 17:22:28 -0500 )edit

yes,I subscribe the image in rviz

Hamid Didari gravatar image Hamid Didari  ( 2013-11-29 01:47:22 -0500 )edit

Did you troubleshoot with image_view?

TFinleyosu gravatar image TFinleyosu  ( 2014-02-11 12:11:24 -0500 )edit

I can subscribe image in rviz .but this program can't subscribe the image. I do not have output from my node. I try cv_bridge in another program work very well but this program doesn't work.

Hamid Didari gravatar image Hamid Didari  ( 2014-02-11 19:57:49 -0500 )edit