Robotics StackExchange | Archived questions

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

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; imagetransport::ImageTransport it; imagetransport::Subscriber imagesub; imagetransport::Publisher imagepub_;

public: ImageConverter() : it(nh) { imagepub = it.advertise("out", 1); imagesub_ = it_.subscribe("in", 1, &ImageConverter::imageCb, this);

cv::namedWindow(WINDOW);

}

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

void imageCb(const sensormsgs::ImageConstPtr& msg) { cvbridge::CvImagePtr cvptr; try { cvptr = cvbridge::toCvCopy(msg, enc::BGR8); } catch (cvbridge::Exception& e) { ROSERROR("cvbridge 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; }

Asked by leoeaton on 2012-06-21 20:13:32 UTC

Comments

Answers