标签:end nbsp 取图 art exec ash cmake uil table
思路:
(1)使用opencv读取本地图像
(2)调用cv_bridge::CvImage().toImageMsg()将本地图像发送给rviz显示
mkdir -p rosopencv/src
cd rosopencv/src
catkin_create_pkg rosopencv sensor_msgs cv_bridge roscpp std_msgs image_transport
cd ..
catkin_make
source ./devel/setup.bash
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <stdio.h>
int main(int argc, char** argv)
{
ros::init(argc, argv, "image_publisher");
ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Publisher pub = it.advertise("camera/image", 1);
cv::Mat image = cv::imread("/home/topeet/test.jpg", CV_LOAD_IMAGE_COLOR);
if(image.empty()){
printf("open error\n");
}
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
ros::Rate loop_rate(5);
while (nh.ok()) {
pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
}
注意:cv::Mat image = cv::imread("/home/topeet/test.jpg", CV_LOAD_IMAGE_COLOR);
这句中的"/home/topeet/test.jpg"
需要改成自己图片的路径.
cd ~/dev/workspace/rosopencv
catkin_make
rosrun rosopencv rosopencv
rostopic echo /camera/image
全是数字。
rosrun rviz rviz
左边点击add
选中image
在image的topic选项中选
/camera/image
转载自:http://blog.csdn.net/ktigerhero3/article/details/70157582
[实例]ROS使用OpenCV读取图像并发布图像消息在rviz中显示
标签:end nbsp 取图 art exec ash cmake uil table
原文地址:http://www.cnblogs.com/chendeqiang/p/7815853.html