在ROS 使用摄像头 WebCam 完成图像处理(1) -- 获取图像数据

在ROS 使用摄像头 WebCam 完成图像处理(1) -- 获取图像数据

我们要使用摄像头,先要能看到摄像头图像:(见附录)

然后我们这里是参考《ros_by_example》( volume1 hydro )书中的方法。
这里要注意的是:虚拟机里的Ubuntu使用cheese, guvcview这样的工具是可以获取图像的,但ros里提供的摄像头驱动,比如uvc_camera, 就不能很好的工作了。

1. 环境搭建的准备工作

ROS组织发布的基础包

开始之前,安装Prerequisites:(是一些ROS组织发布的基础包)

  -----
$ sudo apt-get install ros-hydro-turtlebot-* \
  ros-hydro-openni-camera ros-hydro-openni-launch \
  ros-hydro-uvc-camera \
  ros-hydro-openni-tracker ros-hydro-laser-* \
  ros-hydro-audio-common ros-hydro-joystick-drivers \
  ros-hydro-orocos-kdl ros-hydro-python-orocos-kdl \
  ros-hydro-dynamixel-motor-* ros-hydro-pocketsphinx \
  gstreamer0.10-pocketsphinx python-setuptools python-rosinstall \
  ros-hydro-opencv2 ros-hydro-vision-opencv \
  ros-hydro-depthimage-to-laserscan ros-hydro-arbotix-* \
  git subversion mercurial

  -----
这里有点洒拦河网的感觉,其实可以只安装这几个:
  $ sudo apt-get install ros-hydro-openni-camera \
  ros-hydro-openni-launch \
  ros-hydro-uvc-camera \
     python-setuptools \
  python-rosinstall \

     ros-hydro-opencv2 \
  ros-hydro-vision-opencv \

    git subversion mercurial

1. Installing Webcam Drivers(OPTIONAL)

To use a typical USB webcam, there are a number of possible driver packages available.
The one we will use here is from Eric Perko's repository. Type the following commands
to move into your personal ROS directory, retrieve the source code, then make the
package:

  $ sudo apt-get install git-core
  $ cd ~/catkin_ws/src
  $ git clone https://github.com/ericperko/uvc_cam.git
  $ cd ~/catkin_ws
  $ catkin_make
  
    Tips:如果你是ROS Electric, Fuerte, or Groovy, 自己看《ros_by_example》( volume1 hydro )书吧。

             如果你是Hydro,要用Git 工具下载 rbx1 代码再生成ROS Packages就像former教程写的一样.


2. 用Git 工具下载 rbx1 代码,生成rbx ros Package
    Commands:
$ cd ~/catkin_ws/src && git clone --depth=1 https://github.com/pirobot/rbx1.git
$ cd rbx1 && git checkout hydro-devel
$ cd ~/catkin_ws && catkin_make
$ source ~/catkin_ws/devel/setup.bash

  -----
   git clone 太慢怎么办 ?  所以我这里使用了 --depth=l 进行浅复制
   以上这几行命令,对于你应该很熟悉了,你是有基础的人。这里我们就用了'ROS By Example' 书提供的包了,All of the 'ROS By Example' packages begin with the letters rbx1。
  ===========
  To list the packages,
  move into the parent of the rbx1 meta-package and use the Linux ls command:
    $ roscd rbx1
    $ cd ..
    $ ls -F

  which should result in the following listing:

  rbx1/
  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
好的,订阅ROS摄像头图像并处理可以分为以下几个步骤: 1. 安装ROS和相应摄像头驱动 在开始之前,需要确保ROS已经正确安装,同时需要安装相应的摄像头驱动。以ROS Kinetic和USB摄像头为例,可以使用以下命令安装: ``` sudo apt-get install ros-kinetic-usb-cam ``` 2. 创建ROS包和节点 使用ROS,我们需要创建ROS包和节点来管理我们的程序。可以使用以下命令创建一个名为“camera_processing”的ROS包: ``` catkin_create_pkg camera_processing rospy cv_bridge sensor_msgs ``` 然后可以使用以下命令创建一个名为“image_processor”的ROS节点: ``` rosrun camera_processing image_processor.py ``` 3. 编写代码 在创建了ROS包和节点之后,可以开始编写Python代码来订阅摄像头图像并进行处理。以下是一个基本的代码框架: ```python #!/usr/bin/env python import rospy from sensor_msgs.msg import Image from cv_bridge import CvBridge import cv2 def image_callback(msg): # 将ROS图像消息转换为OpenCV图像格式 bridge = CvBridge() cv_image = bridge.imgmsg_to_cv2(msg, "bgr8") # 进行图像处理 # ... # 显示图像 cv2.imshow("Image window", cv_image) cv2.waitKey(3) def main(): rospy.init_node('image_processor') rospy.Subscriber('/usb_cam/image_raw', Image, image_callback) rospy.spin() if __name__ == '__main__': main() ``` 在上面的代码中,我们首先导入必要的ROS和OpenCV库,然后定义了一个名为“image_callback”的回调函数,用于处理接收到的摄像头图像消息。在回调函数中,我们首先将ROS图像消息转换为OpenCV图像格式,然后进行图像处理,最后显示图像。 在main函数中,我们初始化了ROS节点,然后使用rospy.Subscriber函数订阅了名为“/usb_cam/image_raw”的摄像头图像话题,当有新的图像消息到达时,就会调用我们定义的回调函数进行处理。 4. 运行代码 最后,使用以下命令在终端中运行ROS节点: ``` rosrun camera_processing image_processor.py ``` 如果一切正常,你应该能够看到摄像头的实时图像,并且你的代码可以对图像进行处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值