在ROS 使用摄像头 WebCam 完成图像处理(2) – 初探OpenCV
在ROS 使用摄像头 WebCam 完成图像处理(2) – 初探OpenCV
在上一节,我们通过ros中 uvc_camera 包下的 uvc_camera_node 得到了摄像头的 rgb 图像数据。这些图像数据将送入我们的图像处理 node 进行处理、识别等工作。
OpenCV 是开源的 计算机视觉 算法包,将被用来开发 我们的图像处理 node 。
Install the OpenCV:
The easiest way to install OpenCV under Ubuntu Linux is to get the Debian packages。
$ sudo apt-get install ros-hydro-opencv2 ros-hydro-vision-opencv
If you need a feature found only in the latest version, you can compile the library from source. Instructions can be found here: http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html |
---|
To check your installation, try the following commands:
$ python
>>> from cv2 import cv
>>> quit()
Assuming you do not get an import error, you should be ready to go and you can skip to the next section.
ROS to OpenCV: The cv_bridge Package
A way to process ROS video streams using OpenCV. ROS provides the cv_bridge utility to convert between ROS and OpenCV and image formats.
The Python script cv_bridge.demo.py in therbx1_vision/nodes directory demonstrates how to usecv_bridge.
Before we look at the code, you can try it out as follows.
$ roslaunch rbx1_vision usb_cam.launch device:=/dev/video0
(我用了我们自己写的 usb_cam.launch 而不是 uvc_cam.launch, 目的是避开调用 uvc_cam_node 时产生的错误)
Now run the cv_bridge_demo.py node:
$ rosrun rbx1_vision cv_bridge_demo.py
After a brief delay, you should see two image windows appear. The window on the top shows the live video after been converted to greyscale then sent through OpenCV blur and edge filters. The window on the bottom will remain blank if you are using an ordinary webcam.
Let’s now look at the code to see how it works. file: rbx1_vision/nodes/cv_bridge_demo.py
具体的代码解释就看看 ros by example vol1 的书第10章“Chapter10: Robot Vision”就能懂了。