Passed senesor_msgs Image getting distored while displaying by openCV
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
}