ROS+OpenCV读取图像
新建一个freenect.launch文件,填入一下内容
1 | <launch> |
在ros下创建工作空间
1 | mkdir -p cv_ws/src |
在工作空间下创建程序包
1 | cd src |
1 | 创建程序包的一般格式是catkin_create_pkg <name> <dependencies package> |
在src/robot_vision/src/目录下创建getImage.cpp
1 |
|
- 将ROS消息中的图象信息提取,生成新cv类型的图象,复制给CvImage指针
- cv_ptr = cv_bridge::toCvCopy(msg, “bgr8”);
- cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_16UC1);
- 第二个参数表示转换的类型
- mono8: CV_8UC1, grayscale image
- mono16: CV_16UC1, 16-bit grayscale image
- bgr8: CV_8UC3, color image with blue-green-red color order
- rgb8: CV_8UC3, color image with red-green-blue color order
- bgra8: CV_8UC4, BGR color image with an alpha channel
- rgba8: CV_8UC4, RGB color image with an alpha channel
- cv_ptr->image转化成cv::Mat类型
- ros图片路径
- rgb图片:/camera/rgb/image_raw
- 深度图片:/camera/depth_registered/image_raw
向src/robot_vision/CMakeLists.txt添加如下内容
1 | FIND_PACKAGE(OpenCV REQUIRED) |
编译
- 返回根目录
- 终端输入
catkin_make
运行
- 将节点导入bash,在终端输入
source ./devel/setup.bash
- 打开另一个终端进入之前创建的freenect.launch目录,输入
roslaunch freenect.launch
- 在终端输入运行(rosrun 包名 节点名)
rosrun robot_vision getImage
参考博客