The rate of images converted by cv_bridge is much too low! [closed]

asked 2012-06-21 20:13:32 -0600

leoeaton gravatar image

The tutorials of vision_opencv gives an example to convert ROS images into Opencv images. However, the rate of the images it shows is only 1, while the rate of the topic it subscribes, which cantains the ROS image message, is 15. The example is presented as follows. Could anybody help handle the problem?

namespace enc = sensor_msgs::image_encodings;

static const char WINDOW[] = "Image window";

class ImageConverter { ros::NodeHandle nh_; image_transport::ImageTransport it_; image_transport::Subscriber image_sub_; image_transport::Publisher image_pub_;

public: ImageConverter() : it_(nh_) { image_pub_ = it_.advertise("out", 1); image_sub_ = it_.subscribe("in", 1, &ImageConverter::imageCb, this);

cv::namedWindow(WINDOW);

}

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

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

cv::imshow(WINDOW, cv_ptr->image);
cv::waitKey(3);

image_pub_.publish(cv_ptr->toImageMsg());

} };

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

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by tfoote
close date 2012-06-21 20:54:49