ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to convert an an opencv image using cvBridge??

asked 2012-04-28 05:12:45 -0500

updated 2012-04-28 05:57:30 -0500

Kevin gravatar image

How do I convert an image I have opened through opencv into sensor_msgs/image??

edit retag flag offensive close merge delete


If either of these answers answered your question, please mark one as "correct" so this questions gets closed out ... thanks!

Kevin gravatar image Kevin  ( 2012-04-30 14:16:37 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2012-04-28 05:51:16 -0500

Mac gravatar image

I recommend the cv_bridge tutorials.

edit flag offensive delete link more

answered 2012-04-28 05:54:20 -0500

Kevin gravatar image

updated 2012-04-28 05:56:43 -0500

Here is a snippet of code I have used to do this and the full code is here. It is a package that also uses opencv to grab images and publish them. Some of the variables are:

image_transport::ImageTransport transport;
image_transport::CameraPublisher image_pub;
camera_info_manager::CameraInfoManager info_mgr;

And the code:

        // if subscribers, pub images
        if(image_pub.getNumSubscribers() >  0) {

            ros::Time time = ros::Time::now();

            // convert OpenCV image to ROS message
            cv_bridge::CvImage cvi;
            cvi.header.stamp = time;
            cvi.header.frame_id = "image";
            cvi.encoding = "bgr8";
            cvi.image = cv_image;

            // get camera parameters 
            sensor_msgs::CameraInfo info = info_mgr.getCameraInfo();
            info.header.stamp = cvi.header.stamp;
            info.header.frame_id = cvi.header.frame_id; // whatever it is called
            info.width = cv_image.cols;
            info.height = cv_image.rows;

            sensor_msgs::Image im;
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-04-28 05:12:45 -0500

Seen: 4,607 times

Last updated: Apr 28 '12