Robot Operating System (ROS)
Machine Learning
Robot Operating System (ROS)
Signal processing
3D rendering
Fine-grained parallel computing
Using the turtlebot
Using the kinect sensor
Using rovio robots with ROS
Detecting color blobs in an image
NAO Robot
Using Koala robots with ROS
Using AxisPTZ cameras with ROS
> MALIS Home > Software > Our softs > Robot Operating System (ROS) > Detecting color blobs in an image

MAchine Learning and Interactive Systems

Detecting color blobs in an image
  by Fix Jeremy

In this article, we introduce some nodes of the image_processing ROS package which allow to filter color blobs in an image and to get the contours, bounding boxes and center of mass of the segmented blobs.


In order to make use of the image_processing package, you need to :

  1. Download it from the supelec foundry and catkin make the package :
    cd catkin_workspace/src
    svn checkout --username anonsvn
    cd ..
  1. If everything worked fine, you can play with the nodes color_filter and connected_components

The nodes

The package provide few nodes :

  1. color_filter.cpp : Subscribe to : image [Color image] ; Publish to : color_filtered_image [Boolean image with 0 or 255]
  2. connected_components : Subscribe to : gray_image [Gray image with 0 or 255] ; Publish to : components_image [color image] ; components_com [PolygonStamped] ; components_bbox [image_processing/BBoxArray]

The color_filter node takes a color image and outputs a "boolean" mask with values 0 or 255 ; The parameters can be set with rqt_reconfigure ;

The connected_components extract the connected components from a mask and outputs

  1. an image with the contour around the components in components_image
  2. a set of points which are the center of mass of the components in components_com
  3. the bounding boxes around the components with a custom message in components_bbox The node actually consider only the components with an area larger than a threshold you can set with rqt_reconfigure. You can dynamically select which outputs are produced.


To give a try to the nodes of the package, you can launch the test_components.launch launch file

roslaunch image_processing test_components.launch

This starts a node for getting the image from the webcam, the nodes for filtering the color (color_filter) and the node for extracting the connected components. You can set the parameters on reconfigure panel shown below :

You may see for example the contours of the connected componets :

but you may also listen to the topics /components_bbox :

bash:$ rostopic echo /components_bbox
   x: 402
   y: 411
   width: 103
   height: 67
   x: 1
   y: 287
   width: 90
   height: 191
   x: 92
   y: 279
   width: 159
   height: 199
   x: 240
   y: 148
   width: 253
   height: 320
   x: 582
   y: 38
   width: 56
   height: 74

and the /components_com topic

bash:$ rostopic echo /components_com
 seq: 1205
   secs: 1430333542
   nsecs: 204209309
 frame_id: 0
     x: 205.0
     y: 355.0
     z: 0.0
     x: 63.0
     y: 361.0
     z: 0.0
     x: 393.0
     y: 339.0
     z: 0.0
     x: 453.0
     y: 172.0
     z: 0.0
     x: 603.0
     y: 90.0
     z: 0.0
     x: 624.0
     y: 71.0
     z: 0.0