1. sensor_msgs::Image转Mat
sub节点的回调函数
void chatterCallback(const sensor_msgs
::Image
::ConstPtr
& msg
)
{
cv_bridge
::CvImagePtr cv_ptr
= cv_bridge
::toCvCopy(msg
, sensor_msgs
::image_encodings
::BGR8
);
Mat img
= cv_ptr
-> image
;
cv
::imshow("image", img
);
cv
::waitKey(1);
}
2. Mat转sensor_msgs::Image
pub节点的while循环
while (ros
::ok())
{
Mat image
;
sensor_msgs
::ImagePtr msg
= cv_bridge
::CvImage(std_msgs
::Header(), "bgr8", image
).toImageMsg();
chatter_pub
.publish(msg
);
ros
::spinOnce();
loop_rate
.sleep();
}
Reference: http://wiki.ros.org/image_transport/Tutorials/PublishingImages
转载请注明原文地址: https://yun.8miu.com/read-20429.html