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

Passed senesor_msgs Image getting distored while displaying by openCV

asked 2013-09-12 02:58:22 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I have published an image from one node and then i want to subscribe that image in my second node. But after subscribing it in the second node, when i try to store it in cv::Mat image then, it get distorted.

The patchImage in the following code is distored. there are some horizontal lines and four images of the same image merged.

An overview of my code is following.

first_node_publisher
{
        im.header.stamp = time;
        im.width = width;
        im.height = height;
        im.step = 3*width;
        im.encoding = "rgb8";

        image_pub.publish(im);
} 

second_node_imageCallBack(const sensor_msgs::ImageConstPtr& msg)
{
       cv::Mat patchImage;
       cv_bridge::CvImagePtr cv_ptr;

       try
            { 
                cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::RGB8); //
            }

        catch (cv_bridge::Exception& e)
            {
                ROS_ERROR("cv_bridge exception: %s", e.what());
            }


        patchImage=cv_ptr->image;
        imshow("Received Image", patchImage); //This patchImage is distored
    }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-10-15 08:15:41 -0500

tfoote gravatar image

Are you sure you have the upstream encoding right? That sounds like it's getting interlaced due to wrong step size. A picture would help.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-09-12 02:58:22 -0500

Seen: 168 times

Last updated: Oct 15 '13