How to Detect Blobs using ROS Package cmvision
This page documents how to detect blobs using ROS package cmvision.
Contents |
Obtain and Compile the Source Code
Execute:
$ cd <some ros workspace directory> $ svn co https://code.ros.org/svn/wg-ros-pkg/branches/trunk_cturtle/vision/cmvision $ rospack profile $ roscd cmvision $ rosmake --rosdep-install
Check that the compile process concluded with 0 failures.
Create a colors.txt File to Specify the Blob's Color
Package cmvision uses a file called "colors.txt" to specify the colors of the blob(s). The specification is a combination of RGB and YUV formats as described here. To determine the specification, cmvusion provides a GUI that allows you to visually select the blob.
In this tutorial we use the Logitech Webcam Pro 9000 720p, which attaches to the computer via USB. If you have not done so already, install the usb_cam ROS package.
Open two terminals. On the first terminal, run roscore:
$ roscore
On the second terminal, create a launch file called "colorgui.launch" with the following content (be sure to customize the value of video_device to match your system):
<launch>
<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
<param name="video_device" value="/dev/video0" />
<param name="image_width" value="640" />
<param name="image_height" value="480" />
<param name="pixel_format" value="mjpeg" />
<param name="camera_frame_id" value="usb_cam" />
<param name="io_method" value="mmap"/>
</node>
<node name="colorgui" pkg="cmvision" type="colorgui" respawn="false" output="screen">
<remap from="image" to="/usb_cam/image_raw"/>
</node>
</launch>
Save and exit the launch file, then load it:
$ roslaunch colorgui.launch
The following GUI should appear. Click on the colors that you want to be part of the blob. The color specifications appear at the bottom.
The GUI above shows the view when the camera is facing a white line on the ground. The line is selected and the blob's color is shown at the bottom of the GUI. Specifically, the RGB value is (254, 255, 251) and the YUV range is (252:254, 123:126, 127:129).
Using these values, create a file called "color.txt" in a known location with the following content (more details here):
[colors] (254, 255, 251) 0.000000 1 WhiteLine [thresholds] (252:254, 123:126, 127:129)
You can now exit the color gui and halt the usb_cam node.
Troubleshooting the colorgui Node
Problem: You see the following warnings when running colorgui:
(colorgui:9132): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap"
Solution:
$ sudo apt-get install gtk2-engines-pixbuf
Run the cmvision Blob Finder
Now that we've created a colors.txt file with the blob specification, we can start the cmvision blob finder. Create a launch file called "blobfinder.launch" with the following content (be sure to customize the values of video_device and color_file to match your system):
<launch>
<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
<param name="video_device" value="/dev/video0" />
<param name="image_width" value="640" />
<param name="image_height" value="480" />
<param name="pixel_format" value="mjpeg" />
<param name="camera_frame_id" value="usb_cam" />
<param name="io_method" value="mmap"/>
</node>
<node name="cmvision" pkg="cmvision" type="cmvision" respawn="false">
<remap from="image" to="/usb_cam/image_raw"/>
<param name="color_file" value="/path/to/color.txt" />
<param name="mean_shift_on" value="false" />
<param name="color_radius_pix" value="0" />
<param name="spatial_radius_pix" value="0" />
<param name="debug_on" value="false" />
</node>
</launch>
Ensure roscore is running, then run the launch file:
$ roslaunch blobfinder.launch
If you run cmvision in debug mode (i.e., set the value of parameter /cmvision/debug_on to be "true"), the following GUI should appear showing you the blob that was detected:
The cmvision blobfinder will now be publishing blob information on topic "/blobs".
Using the Blob Data
You can see the blob data being published using the following command:
$ rostopic echo blobs
Here is example output:
header:
seq: 310
stamp:
secs: 1329693736
nsecs: 860846102
frame_id: ''
image_width: 640
image_height: 480
blob_count: 2
blobs:
-
red: 254
green: 255
blue: 251
area: 27577
x: 288
y: 263
left: 227
right: 333
top: 0
bottom: 479
-
red: 254
green: 255
blue: 251
area: 34
x: 281
y: 70
left: 278
right: 284
top: 66
bottom: 75
---

