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

sensor_msgs::CvBridge::cvToImgMsg in Groovy?

asked 2013-04-09 00:02:52 -0600

Javier J. Salmerón García gravatar image

updated 2014-01-28 17:16:06 -0600

ngrennan gravatar image

Hello everyone,

Following the tutorial in Ros Wiki for creating a simple image publisher (from a set of .png files) http://ros.org/wiki/image_transport/Tutorials/PublishingImages I found a compilation error in groovy (in fuerte everything works fine):

cv::WImageBuffer3_b image(cvLoadImage(filePath.c_str(), CV_LOAD_IMAGE_COLOR));
sensor_msgs::ImagePtr msg = sensor_msgs::CvBridge::cvToImgMsg(image.Ipl(), "bgr8");

This is the error I found:

 error: ‘sensor_msgs::CvBridge’ has not been declared

I suppose that the API has changed, but I cannot find an alternative way. Can somebody help me?

Thank you in advance

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2013-04-09 02:13:59 -0600

Javier J. Salmerón García gravatar image

updated 2013-04-09 02:14:34 -0600

I managed to sort it out the following way, using this answer as a reference http://answers.ros.org/question/9765/how-to-convert-cvmat-to-sensor_msgsimageptr/?answer=14282#post-id-14282 :

cv::WImageBuffer3_b image(
                    cvLoadImage(filePath.c_str(), CV_LOAD_IMAGE_COLOR));
            cv::Mat imageMat(image.Ipl());


            cv_bridge::CvImage out_msg;
            out_msg.encoding = sensor_msgs::image_encodings::BGR8; 
            out_msg.image    = imageMat;
            out_msg.header.seq = i;
            out_msg.header.frame_id = i;
            out_msg.header.stamp = ros::Time::now();

            ci->header.seq = i;
            ci->header.frame_id = i;
            ci->header.stamp = out_msg.header.stamp;

            pub.publish(out_msg.toImageMsg(), ci);
edit flag offensive delete link more

Comments

What does i refer to? I am trying to convert Mat to sensor_msgs::image need help with header values.

balakumar-s gravatar image balakumar-s  ( 2013-09-07 00:56:46 -0600 )edit
0

answered 2013-06-09 20:29:19 -0600

Refer to ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages#cv_bridge.2BAC8-Tutorials.2BAC8-UsingCvBridgeCppDiamondback.Converting_OpenCV_images_to_ROS_image_messages for the recommended solution to this problem, the code should look something like:

sensor_msgs::ImagePtr msg;
image.Ipl().toImageMsg(&msg);
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2013-04-09 00:02:52 -0600

Seen: 1,891 times

Last updated: Jun 09 '13